Select Sheet Code Name

Marhier

Board Regular
Joined
Feb 21, 2017
Messages
128
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Good afternoon, I hope you're all well.
I'm having an issue with a bit of VBA, where all it's doing is selecting another worksheet.

Typically, I would have used:
VBA Code:
Sub CallSheet()
Sheets("Example").Select
End Sub

As users sometimes change the worksheet's name, I wanted to use the sheet's codename - Example, I've called it "Page"
Using the code:
VBA Code:
Sub CallSheet()
Page.Select
End Sub

When I do this, it's giving me a "Reference is Invalid" error.

Can someone let me know what I'm doing wrong here?

Much appreciated.
Thank you.
Regards
Marhier
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Is the code in the same workbook as the sheet?
 
Upvote 0
Hello !​
Is the worksheet located in the workbook containing this VBA procedure ?​
 
Upvote 0
Hi Fluff & Marc L
The code is located in a module called ButtonFunctions
 
Upvote 0
The question they were asking is whether that module is in the same workbook as the sheet you are trying to select? If not, you can't use the codename (at least not without setting a reference).
 
Upvote 0
And if you look at the project explorer window for that workbook you have something like Page (Example)
 
Upvote 0
The code should be fine then. Do you have any other event code, like Worksheet_Activate? Or hyperlinks assigned to the buttons?
 
Upvote 0
Solution
The buttons had a hyperlink on them.
This has solved my problem, lol.

Thanks mate.
I'd have never of realised that without your help, as I knew the code I was typing was right!

Thanks again
Regards
Marhier
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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