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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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