Macro code to reference workbooks

aa2000

Board Regular
Joined
Aug 3, 2011
Messages
87
Hi all

As the title says, I'm trying to reference one workbook from the macro code of another workbook.
The macro code is comparing values on 2 workbooks and the one in which the code is written is the active workbook.

Code:
Set Erng2 = ActiveWorkbook.Sheet5.Range("R1:R50")
Set Erngr2 = Workbooks(Filename.xls).Sheet6.Range("A1:A20")

Is this the correct code to reference the two workbooks?

Cheers
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Perhaps

Code:
Set Erngr2 = Workbooks("Filename.xls").Sheet6.Range("A1:A20")
 
Upvote 0
When I run this sub I get Run time error 438 "Object Doesn't support this property or method" and that line is higlighted. Any ideas why?

Cheers
 
Upvote 0
You are right - it doesn't seem to like using sheet codenames for other than the active workbook.

Maybe

Code:
Set Erngr2 = Workbooks("Filename.xls").Sheets(6).Range("A1:A20")
 
Upvote 0
That does work fine for the workbook I am using to test these codes on, but when I try it on the actual workbook, which was created in germany, on a german version of xp, it fails. I presume its due to me not knowing the plural of sheets in german :)

Anyway thank you for you help!
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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