Refer to another workbook's worksheet codename

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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