Refer to another workbook's worksheet codename

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Is it possible to refer to a worksheet's codename if it's in another workbook?

If the workbook I am trying to open contains a worksheet called "Data" and its codename is "wksData" then this works:

Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Workbooks.Open C:\MyLocation\MyFile.xlsm[/FONT]

Dim wb As Workbook
Set wb = Activeworkbook

Dim i As String

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]i = wb.Worksheets("Data").Range("A1").Value

but this fails:

Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Workbooks.Open C:\MyLocation\MyFile.xlsm
[/FONT]
Dim wb As Workbook Set wb = Activeworkbook Dim i As String
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
i = wb.wksData.Range("A1").Value


How can I refer to the "other" workbook's worksheet using its codename?

Thanks


[/FONT]<strike>
</strike>
[/FONT]
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If you set a reference to the other workbook's project, then you can refer to the other sheet using projectname.codename syntax (you will need to have changed the project name from the default VBAProject in order to set a reference). Otherwise you'll need a looping function such as the one Dave linked to.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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