How to include an integer variable in a workbook name VBA?

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I would like to be able to include a variable value in part of a workbook name. The line of code requiring a variable value (the workbook name changes each time the file is accessed) is below:

Code:
Set GLD = Workbooks("GLD_US_archive_EN(integer variable goes inside the brackets).csv")

what is the syntax for including an integer variable in this situation?

Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try
Code:
Set GLD = Workbooks("GLD_US_archive_EN" & myVariable & ".csv")
 
Upvote 0
When I write the line as:

Code:
Set GLD = Workbooks("GLD_US_archive_EN(" a ").csv")

I receive a compile error expected: list separator or )

How can I get around this while continuing to include the variable inside of the brackets?
 
Upvote 0
The same way I showed you, just add the brackets
 
Upvote 0
Code:
Set GLD = Workbooks("GLD_US_archive_EN(" [COLOR="#FF0000"]&[/COLOR] a [COLOR="#FF0000"]&[/COLOR] ").csv")
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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