Define workbook name as variable

sweeneytime

Board Regular
Joined
Aug 23, 2010
Messages
183
Hi,

I wish to set up a macro in a workbook - reports. This will copy info from another wb many times - results. The name of the reports wb will change. Therefore I wish to declare the wb name when I run the macro.

I have tried the following.

The workbook name is returned in D3.

HTML:
Dim Reports As Workbook
    
 Reports = Sheets("Conserv").Range("D3").Value

&
HTML:
Reports = activeWorkbook.name

Would someone be able to suggest a solution please?

Thanks,
Alan
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Dim Reports As Workbook
Set Reports = Sheets(Sheets("Conserv").Range("D3").Value)
 
Upvote 0
Thanks for that, but I get a "run time error 9" now.

I have used a formula to return the address in the wb so I though it would be correct. I double checked the sheet reference too in the complier.
 
Upvote 0
I am very sorry. Instead of Sheets, I should write Workbooks. Here's correction:
Code:
Dim Reports As Workbook
Set Reports = Workbooks(Sheets("Conserv").Range("D3").Value)
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,904
Members
452,948
Latest member
Dupuhini

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