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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,963
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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")
 

zuki

New Member
Joined
Sep 2, 2012
Messages
22
The problem was indeed with the extension! You are a genius! Do you know why it is sometimes necessary to include it?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,963
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

zuki

New Member
Joined
Sep 2, 2012
Messages
22
Thank you very much! I have no idea how I would have found out if it was not for you :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,109
Messages
5,857,443
Members
431,879
Latest member
KiwDaWabbit

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
Top