VBA Set Workbook Name in Code from Cell Value

JoyMaree

New Member
Joined
Sep 12, 2018
Messages
18
I have 2 workbooks open and I am running code from Workbook 1 to copy and paste data into Workbook 2.
The problem is Workbook 2's name changes every month and the Worksheet changes every day.
I can't use Active Workbook as I have 2 open and i am running the Macro from Workbook 1.



Set Claim_Reg = Workbooks("Workbook 2 September 2018.xlsx")
Set Daily = Claim_Reg.Worksheets("13 Sep 2018")
Set Alloc_Details = Workbooks("Workbook 1.xlsm")
Set Alloc = Alloc_Details.Worksheets("Allocation")

I would like to have a cell in the Workbook 1 on a Tab called "Parameters" that I can change every day.

Any help would be appreciated.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Maybe this will get you started:


Code:
[COLOR=#333333]Set Alloc_Details = Workbooks("Workbook 1.xlsm")
[/COLOR][COLOR=#333333]Set Alloc = Alloc_Details.Worksheets("Allocation")
[/COLOR]Set Params = Alloc_Details.[COLOR=#333333]Worksheets("[/COLOR][COLOR=#333333]Parameters[/COLOR][COLOR=#333333]")
[/COLOR]
[COLOR=#333333]Set Claim_Reg = Workbooks(params.range("b3").value) 'assumes you have the name of this workbook on params sheet in cell b3[/COLOR]
[COLOR=#333333]Set Daily = Claim_Reg.Worksheets(params.range("b4").value) [/COLOR][COLOR=#333333]'assumes you have the name of this worksheet on params sheet in cell b4[/COLOR]
 
Upvote 0
Thank you so much. It works perfectly.
I have been searching threads for a couple of hours and couldn't find anything to solve the problem.
Much appreciated.
 
Upvote 0
Hi Odin,

Is it possible to have "B3" as a formula?
The code above works if it is text but not if I formulate the sheet name to change each month.

Tks
JoyMaree
 
Upvote 0
Hi Joy,

I'm a bit confused. Even if you have a formula in B3 to create a workbook name, the vba would grab whatever that formula resolved to. For example, if B3 has the formula
Code:
 ="[COLOR=#333333]Workbook 2"  & " September 2018.xlsx" [[/COLOR]/CODE]  the vba would grab "[COLOR=#333333]Workbook 2 September 2018.xlsx"

B3 must have a valid workbook (not worksheet) name, that is already opened along with workbook 1.


[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,566
Members
453,053
Latest member
Kiranm13

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