Sheet selection on Autoclose

Hi all,

i was wondering whether if anyone can help me on this problem.

I have this macro that protects the spreadsheet at worksheet and workbook 
level when i close spreadsheet, however, i discovered a problem when i have 
mutiple spreadsheets opened together with this particular sheet and exiting 
excel all together at once. The macro instead of targeting and running the 
macro for the worksheet it opened with, will just work for top-most opened 
spreadsheet which i am closing from. I do not want to hardcode the name of 
the spreadsheet into the macro as this is a generic macros that i use for a 
lot of my spreadsheets and my spreadsheet will be renamed from time to time.

Would really appreciate any help that can be given. Thanks

-----------------------------------------------------------------------------------------------
Sub Auto_close()

Application.DisplayAlerts = False

On Error Resume Next
    lastSheet = ActiveWorkbook.Sheets.Count
    For curSheet = 1 To lastSheet
        Application.Sheets(curSheet).Activate
        ActiveSheet.Protect ("12345")
    Next
    Sheets("Main").Select
    Range("A1").Select
    ActiveWorkbook.Protect ("12345")

End Sub

----------------------------------------------------------------------------------------------

Rgds
Ray
0
Utf
11/26/2009 3:22:01 AM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
730 Views

Similar Articles

[PageSpeed] 58

I think I'd tweak it this way

Dim myWS as Excel.Worksheet

For each myWS in ThisWorkbook.Worksheets
     myws.protect("12345")
next myWS
-- 
HTH,

Barb Reinhardt



"swiftcode" wrote:

> Hi all,
> 
> i was wondering whether if anyone can help me on this problem.
> 
> I have this macro that protects the spreadsheet at worksheet and workbook 
> level when i close spreadsheet, however, i discovered a problem when i have 
> mutiple spreadsheets opened together with this particular sheet and exiting 
> excel all together at once. The macro instead of targeting and running the 
> macro for the worksheet it opened with, will just work for top-most opened 
> spreadsheet which i am closing from. I do not want to hardcode the name of 
> the spreadsheet into the macro as this is a generic macros that i use for a 
> lot of my spreadsheets and my spreadsheet will be renamed from time to time.
> 
> Would really appreciate any help that can be given. Thanks
> 
> -----------------------------------------------------------------------------------------------
> Sub Auto_close()
> 
> Application.DisplayAlerts = False
> 
> On Error Resume Next
>     lastSheet = ActiveWorkbook.Sheets.Count
>     For curSheet = 1 To lastSheet
>         Application.Sheets(curSheet).Activate
>         ActiveSheet.Protect ("12345")
>     Next
>     Sheets("Main").Select
>     Range("A1").Select
>     ActiveWorkbook.Protect ("12345")
> 
> End Sub
> 
> ----------------------------------------------------------------------------------------------
> 
> Rgds
> Ray
0
Utf
11/26/2009 3:35:01 AM
Hi Barb,

It works! Thanks

Rgds
Ray

"Barb Reinhardt" wrote:

> I think I'd tweak it this way
> 
> Dim myWS as Excel.Worksheet
> 
> For each myWS in ThisWorkbook.Worksheets
>      myws.protect("12345")
> next myWS
> -- 
> HTH,
> 
> Barb Reinhardt
> 
> 
> 
> "swiftcode" wrote:
> 
> > Hi all,
> > 
> > i was wondering whether if anyone can help me on this problem.
> > 
> > I have this macro that protects the spreadsheet at worksheet and workbook 
> > level when i close spreadsheet, however, i discovered a problem when i have 
> > mutiple spreadsheets opened together with this particular sheet and exiting 
> > excel all together at once. The macro instead of targeting and running the 
> > macro for the worksheet it opened with, will just work for top-most opened 
> > spreadsheet which i am closing from. I do not want to hardcode the name of 
> > the spreadsheet into the macro as this is a generic macros that i use for a 
> > lot of my spreadsheets and my spreadsheet will be renamed from time to time.
> > 
> > Would really appreciate any help that can be given. Thanks
> > 
> > -----------------------------------------------------------------------------------------------
> > Sub Auto_close()
> > 
> > Application.DisplayAlerts = False
> > 
> > On Error Resume Next
> >     lastSheet = ActiveWorkbook.Sheets.Count
> >     For curSheet = 1 To lastSheet
> >         Application.Sheets(curSheet).Activate
> >         ActiveSheet.Protect ("12345")
> >     Next
> >     Sheets("Main").Select
> >     Range("A1").Select
> >     ActiveWorkbook.Protect ("12345")
> > 
> > End Sub
> > 
> > ----------------------------------------------------------------------------------------------
> > 
> > Rgds
> > Ray
0
Utf
11/26/2009 3:58:01 AM
Reply:

Similar Artilces:

How can I share information between multiple sheets in Excel?
New question: I know now how to use "=sheet1!a1" to copy cells from sheet 1 to sheet 2,3 etc. Is there is a formula that will allow me to enter data into sheet 2, and have it copy automatically into sheet 1 and 3, or into sheet 3 going to sheet 1 and 2? So that I can enter the data into any sheet and have it transfer to all sheets, rather than always from sheet 1 to sheets 2 and 3. Nothing built into excel (except for the formula you showed). But I'd be very hesitant to separate my data. I'd do my best to keep all the data on one worksheet. You can use Data|Fi...

Call from a different sheet?
I'm wondering if it's possible in Excel to call data from a different sheet. For example if I changed A1 in sheet 2 it'd affect forumlas in sheet 1. -- HisHighness ------------------------------------------------------------------------ HisHighness's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=31454 View this thread: http://www.excelforum.com/showthread.php?threadid=511552 You can link to another worksheet with a formula like ='Sheet1'!A1 -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson...

Transfer the total of mutiple entries in a sheet to another sheet in the same file #2
How to transfer the total of multiple of multiple entries in a sheet to another shet in the same file. Please help me in this formula ** Posted via: http://www.ozgrid.com Excel Templates, Training, Add-ins & Software! http://www.ozgrid.com/Services/excel-software-categories.htm ** ...

HOW DO I CHANGE THE ORDER OF THE SHEETS IN EXCEL WORKBOOK?
my sheets are not in the order I want them. How do I change the order. The data is already in the sheets. Click on the tab and drag it to where you want to. -- Regards Ken....................... Microsoft MVP - Excel Sys Spec - Win XP Pro / XL 97/00/02/03 ------------------------------�------------------------------�---------------- It's easier to beg forgiveness than ask permission :-) ------------------------------�------------------------------�---------------- "joanbaer" <joanbaer@discussions.microsoft.com> wrote in message news:1F45...

Max number sheets in a file?
How many sheets can an excel 2002 file have if each sheet has only abou a page of text? I'm just looking for a general idea, if it's lots an lots and I don't need to worry about it that's a good enough answer fo m -- Message posted from http://www.ExcelForum.com The number will be limited by the memory in your computer. Certainly hundreds of sheets is well within most machine's capacity. In article <bishopwill.154u1g@excelforum-nospam.com>, bishopwill <<bishopwill.154u1g@excelforum-nospam.com>> wrote: > How many sheets can an excel 2002 file hav...

Sheet to sheet copying
Hi, I have two spreadsheets. One called nursing and the other medical. I want to be able to copy certain cells from one sheet to other and visa verca without the need to copy & paste. So I want a cell in nursing to search a column for specific text in the medical sheet, then I want the contents of cells in the row where the text is found to be copied to cells in the nursing sheet. Example: The cells B3-G3 in the nursing sheet to search Column A in the medical sheet for specific text e.g. "G1". When "G1" is found in cell A5 then the contents of cells B5-G5 in t...

Select 'Sort By' column by simply typing heading letter
Hello, In the next version of MS Excel, please restore the ability to define Sort By columns by simply typing the Column heading letter as was the case in Word 2003. When Excel 2007 came out, I was astonished to discover that capability was no longer available. For example, suppose I want to sort a large spreadsheet by Column CDX. In both Excel 2003 and 2007, if I open the Sort box and click Sort By, the drop down menu, by default, lists Column A as the first option. In Excel 2003, I could simply click twice to insert the cursor, type backspace (to remove the A), then ...

Check Register to Mortgage Sheet
Hi; I am using MS Money 2007. If I write a check in my register to my mortgage company, how do I get that transaction to update my mortgage account register? Do I have to type it in twice (Once to my check register and once to my mortgage register)? I would like to set some stuff up where items in my check register automatically cary to other account items. Thanks for any advice on this. Pat From the Check Register make it a transfer to your Mortgage Account. -- Regards Bob Peel, Microsoft MVP - Money For UK tips & fixes see http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mn...

list sheet comments
Hi, I have a sheet with a lot of comments. I would like to create a macro that lists all the comments of the sheet in column F. I=B4ve tried something similar like this: For Each cmt in ActiveSheet.Comments MsgBox cmt.Text Next cmt But I don=B4t know how to list each comment in each cell of column F instead of a msgbox. thanks Dim StartCell as Range dim Cmt as comment with activesheet set startcell = .range("F1") for each cmt in .comments startcell.value = cmt.txt 'come down to the next cell set startcell = startcell.offset(1,0) n...

blank out rest of work sheet
I was wondering how to blank out the empy cells in my worksheet. For example: I have data in columns A-F down about 50 rows. I do not want to see any rows past that. When I am saving the data as a text file, I am getting extra rows in my file for some reason and I want to see if this would prevent this from happening. Thanks... --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.769 / Virus Database: 516 - Release Date: 9/24/2004 Hi Shawn, See the explanation and remedial notes on Debra Dalgleish's web site: ...

How to populate one sheet with data from another sheet
I have 2 sheets in the excel file. On the first sheet the first colum is a part num only. The second sheet has part num on the first column and descriptions on the second column. I need a macro or script that will scan the second sheet for part num that matches the first sheet part num and populate the description(at the second column) on the first excel sheet. -- KH One way .. Assuming the reference data is in Sheet2, cols A and B col A = part#, col B = description In Sheet1 ----------- With col A containing part# in A2 down, Put in B2: =IF(ISNA(MATCH(A2,Sheet2!A:A,0)),"&quo...

No Bound Sheets Found Error Dialog Box-Excel 2000
Hello all. I have a 8.5MB spreadsheet that is the summary of weekly timesheets that are Excel files. I have attempted various strategies to reduce the size of the files. This sheet is all references to other worksheets. Up until two days ago, when opening the file and it asks, this contains references to other files...do you want Excel to update the cell refences, y or N. I always hit okay and it does it's stuff. Now however, when the box comes up when opening the file, I hit okay and it returns a "No Bound Sheets" error dialog box. All I can do is hit okay and a...

Changing from sheet to sheet
Hi there! Is there a function that would enable me to navigate from sheet to sheet in an Excel document (instead of using the mouse and click on the sheet I want to work with)? Many thanks! Hi Ctrl PgUp and Ctrl PgDwn is one way. Insert > Hyperlink (and after that clicking it) is another. HTH. Best wishes Harald "Greywolf" <anonymous@discussions.microsoft.com> skrev i melding news:5bfc01c42d6b$c2a26630$a101280a@phx.gbl... > Hi there! > > Is there a function that would enable me to navigate from > sheet to sheet in an Excel document (instead of using the &...

Delete values in sheet 2 that arre found in sheet 1
Is there an easy way to delete values in sheet 2 that match the value from sheet 1. I have approximately 10000 rows in sheet 1 and some identical rows on sheet 2 that need to be eliminated? I not sure if this has to be done pragmatically or if there is some feature in excel 2007 that can handle this type of request. thanks Nick If it is the values in a single column on each sheet that make up the duplication, it's fairly easy. Lets say you want to compare the contents of column A on each sheet to find duplicates on Sheet2 (that are also on Sheet1). Your data starts o...

Function to Copy all sheets into one sheet
Is there a way to copy multiple sheets at once to create one worksheet, rather than one at a time? You could use a for/each loop for each ws in worksheets depends on what and where you want to copy next -- Don Guillett SalesAid Software donaldb@281.com "Des" <cusaty@express-scripts.com> wrote in message news:013801c3b43a$5cb403b0$a101280a@phx.gbl... > Is there a way to copy multiple sheets at once to create > one worksheet, rather than one at a time? ...

Linking sheets
I am trying to hyperlink a cell in one single sheet spreadsheet to a specific sheet in another multisheet book. I don't need to get to any specific cell in the second spreadsheet, just the specific sheet. Thx, Chris In Excel 2003 or earlier. Insert>Hyperlink>Existing file or webpage. Browse to the target workbook then hit "Bookmark" and pick a sheet and a cell. Gord Dibben MS Excel MVP On Thu, 22 May 2008 19:14:38 -0700 (PDT), spacia <chris_butler@thegrid.net> wrote: >I am trying to hyperlink a cell in one single sheet spreadsheet to a >specific sheet in...

Copying Drown Dop Box Selections
I've been using drop down boxes (or list) boxes in several of my spreadsheets to help with data input. I need to copy data entered including the drop down box selection into another spreadsheet or into MS Word. I can't figure out how to copy the drop down selection. Thoughts? P.S. I don't program in visual basic. Thanks! -- scottrichards7 ------------------------------------------------------------------------ scottrichards7's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=27421 View this thread: http://www.excelforum.com/showthread.php?thread...

Limiting the number of selections in a List Box Control
Hi Folks, I have a list box (multiselect = simple) that is dynamically populated by a query. I want the user to select only two items from the list and then i want to use these two items to run another quesry which will be the source data for a report. How do i force the List Box to allow only two selections? Regards, John Dumay On Sun, 30 Dec 2007 20:44:01 -0800, John Dumay wrote: > Hi Folks, > > I have a list box (multiselect = simple) that is dynamically populated by a > query. I want the user to select only two items from the list and then i want > to use these ...

Insert Picture from dropdown selection
I'm working at a Marina and trying to make a comparison chart for different types of boats. I am trying to make a list, and based upon the users selection of a boat, insert a corresponding picture to match the boat selected from that list. I've researched other thread discussions, and tried to approach it this way, as reccommended by Ron Coderre: Select Sheet2 and turn off Grid Lines (Tools>Options>View tab:Uncheck Grid Lines) 1)For each picture to be displayed: 1a. Insert>Picture from file. (select picture, put it in the sheet and resize it). 1b. Select the range of cel...

Saving Excel Sheet
I have a series of worksheets that I use to generate a quotation. I would like to use these worksheets like a template but when saved I only want to save the results in a separate file is this possible? If you look up Template in Help there is quite a good explanation of how to create and use a template. -- Regards, OssieMac "dragons_lair" wrote: > I have a series of worksheets that I use to generate a quotation. I would > like to use these worksheets like a template but when saved I only want to > save the results in a separate file is this possible? ...

how to invoke select names form
hi all... i want to invoke the form(Select Names form that will be opened when we click the To button in the new mail message) programatically in my form ... how can i do this ... I don't think you can as it is not a form but a cache of addresses = previously used in the TO: field - however, you can always ask in a = programming group "down the hall." --=81 Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. =20 After furious head scratching, Malli asked...

move to other sheet
I would like to move certain rows from one sheet to another. For example: If there are in column A cells containing "DC BMW" move the row that goes with it to sheet named DC BMW. Fen Dag fen Start here if you want to do it with VBA code http://www.rondebruin.nl/copy5.htm Groeten Ron -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "fen" <f.klompsma@upcmail.nl> wrote in message news:59225$4bb37f3b$d55d9af3$26184@news.chello.nl... > I would like to move certain rows from one sheet to another. > For example: If there a...

Re: Unprotecting Sheets
Is it possible to unprotect all sheets in a workbook at the same time? Zee, You could use VBA to cycle through all the sheets that are protected and unprotect them that way. Don't think it is possible without code. -- http://www.ExcelHelp.us ed@ExcelHelp.us 888-MY-ETHER ext. 01781474 "Zee" wrote: > Is it possible to unprotect all sheets in a workbook at the same time? Unfortunately I am not very familiar with VBA and therefore am not sure what to enter into the editor to accomplish this. "galimi" wrote: > Zee, > > You could use VBA to cycle thr...

how do I create a spread sheet to automatically calculate when I
On a new spread sheet I am entering numbers and I would like them to be multiplied and changed automatically. The formula is x*3 then less 40%. Can anyone help me. One way: If you are entering your numbers in column A, say, then in column B enter: B1: =(A1*3)*(1-40%) or, better, B1: =A1*3*60% copy B1 down as far as necessary. In article <678FA28E-14A7-40E5-B0DF-54D574F9F7E3@microsoft.com>, wbinfo <wbinfo@discussions.microsoft.com> wrote: > On a new spread sheet I am entering numbers and I would like them to be > multiplied and changed automatically. The f...

moving from sheet to sheet
I need to write code that automatically moves from sheet to sheet and gathers data. I have no problem gathering the data on the sheet but I don't know how to move the pointer to the next sheet in the workbook. I would really appreciate any help you can give. -- Bob A Sub moveSheetToSheet() Dim ws As Worksheet For Each ws In ThisWorkbook.Sheets MsgBox ws.Name Next End Sub "Bob A" wrote: > I need to write code that automatically moves from sheet to sheet and gathers > data. I have no problem gathering the data on the sheet but I don't know h...