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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,215,671
Messages
6,126,131
Members
449,293
Latest member
yallaire64

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