Worksheet reference does not work on all computers

zuki

New Member
Joined
Sep 2, 2012
Messages
22
I have the following strange problem:
In a visual basic code i do references like: Workbooks("WorkbookX").Worksheets("WorksheetY").DoSomething
And they work fine. For some other people when running it does not find the worksheet i.e. gives the same error as if I had written
Workbooks("WorkbookX").Worksheets("WorksheetZ").DoSomething
where WorksheetZ does not exist. It helps if I change to the generic naming in excel i.e. Sheet8, Sheet9 but it would be quite cumbersome to change all references.
Does anyone have an idea?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Are you sure it's the Worksheet reference it's objecting to and not the Workbook one? It's better to supply the extension too:
Rich (BB code):
Workbooks("WorkbookX.xlsx").Worksheets("WorksheetY")
 
Upvote 0
The problem was indeed with the extension! You are a genius! Do you know why it is sometimes necessary to include it?
 
Upvote 0
If a computer has Windows Explorer set to show file extensions, you have to include it in your code. If you include it anyway, it will work regardless of the explorer settings.
 
Upvote 0
Thank you very much! I have no idea how I would have found out if it was not for you :)
 
Upvote 0

Forum statistics

Threads
1,217,386
Messages
6,136,283
Members
450,002
Latest member
bybynhoc

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