Activate sheet on workbook open

Agent_V

New Member
Joined
Aug 24, 2007
Messages
19
Could someone please advise me on how to activate a particular sheet as part of the workbook_open event. At the moment it doesn't matter how I try to code it I get Run-time error '1004': Select method of Worksheet class failed.

I have tried:
Sheets("Sheetname").Activate
Sheets("Sheetname").Select
ActiveWorkbook.Sheets("Sheetname").Activate
ActiveWorkbook.Sheets("Sheetname").Select
ThisWorkbook.Sheets("Sheetname").Activate
ThisWorkbook.Sheets("Sheetname").Select
ThisWorkbook.Worksheets("Sheetname").Activate
ThisWorkbook.Worksheets("Sheetname").Select

and they all return the same error.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
All of those should work. Is the sheet hidden - if so you need to unhide it first.
 
Upvote 0
The sheet is not hidden, but I have just managed to figure out that the error only occurs if VB Editor is open. If the workbook is opened and VB Editor is closed then it works fine. I don't understand, why should VB Editor have anything to do with this?
 
Upvote 0
Thanks montecarlo2079, but in my scenario the code wouldn't even get to the range select line because is errors on the sheet select.

For anyone else looking at this a bit more hunting makes me believe it has something to do with the different warning behaviour of Excel 2010 depending on whether the VB Editor is open. When the VB Editor is closed, the only warnings I get are Enable Editing and Enable Content in the yellow bars across the top of the spreadsheet and beneath the ribbon. However, when VB Editor is open a pop up dialog box asking you to Enable Macros is presented. I think this must be stealing the focus (or something like that) away from the workbook, so that the macro is unable to determine what to select.

If my theory is any way plausible, would anyone know how to fix it?
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top