Unable to Open My Workbook at a Specific Tab

DavidWF

Board Regular
Joined
Oct 14, 2015
Messages
130
I'd appreciate guidance with the following.

I'm trying to open a workbook at a specific tab, using:

Code:
Private Sub Workbook_Open()

Sheets(“Sheet26”).Select

Range(“B2”).Select

End Sub

in ThisWorkbook, however every time I open the workbook it opens at the last used tab and displays an error pop-up - Run-time error '9': Subscript out of range

Running Debug highlights the
Code:
Sheets("Sheet26").Select
line. I've tried replacing "Sheet26" with the actual tab name but I get the same result.

What have I done wrong and what should I have done?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
if you look at the vba, to the left, you see the name of the project, down that list will be the name and its sheet number, makes sure you are addressing the right sheet, adding and removing sheets can mean what worked now no longer references what you expected
 
Upvote 0
The sheet listing at the left definitely shows Sheet26 being present. The tab name is Index so I've tried
Code:
Sheets(“Sheet26”).Select
and I've tried
Code:
Sheets(“Index”).Select

I get the error pop-up in both cases
 
Upvote 0
You are looking at its codename so try just

Code:
Sheet26.Select

For the Index part open your Immediate window if not already open, run the code below and copy the result to the thread.

Code:
Sub testit()
Debug.Print "< &"; Sheet26.Name; "& >", Len(Sheet26.Name)
End Sub
 
Last edited:
Upvote 0
Thanks Mark - that now opens the workbook at the correct tab, but now there's a new error - the
Code:
Range(“B2”).Select
line.
Now it's Run-time error '1004' Method 'Range' of object '_Global' failed
 
Upvote 0
The sheet listing at the left definitely shows Sheet26 being present. The tab name is Index so I've tried
Code:
Sheets(“Sheet26”).Select
and I've tried
Code:
Sheets(“Index”).Select

I get the error pop-up in both cases

when referring to the sheet number instead of the name of the sheet i dont think you use quotation marks

Code:
Sheets(26).Select

i have no idea why using the name of the sheet "Index" isnt working for you though
 
Upvote 0
Thanks Mark - that now opens the workbook at the correct tab, but now there's a new error - the
Code:
Range(“B2”).Select
line.
Now it's Run-time error '1004' Method 'Range' of object '_Global' failed

Other than you have some strange quote marks around B2 (which I deleted and retyped) I don't get the issue.
Do you have any sheet protection or merged cells?

or try

Code:
Private Sub Workbook_Open()
Application.Goto Sheet26.Range("B2"), True
End Sub
 
Last edited:
Upvote 0
Sorry Mark, I missed seeing the second part of your reply. The result from the Immediate Window was:

Code:
< &Index& >    5
 
Upvote 0
Sorry Mark, I missed seeing the second part of your reply. The result from the Immediate Window was:

Code:
< &Index& >    5

I would check the quote marks in your code on that as well then.
 
Upvote 0
Thanks Mark

Code:
Application.Goto Sheet26.Range("B2"), True

solved the problem. The workbook now opens correctly.

No idea what the issue with the quote marks might be - maybe because we're upside down on this side of the planet.

Thanks guys for your comments and assistance.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,809
Members
449,048
Latest member
greyangel23

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