Using a Variable in the Workbooks.Open code

  • Thread starter Thread starter Phatchef24
  • Start date Start date
P

Phatchef24

I was wondering if it was possible to use a variable when using the Ope
workbook code. I already have the file name that I need declared as
variable in my code already and now all I need to do is place that nam
at the end of this code.

Workbooks.Ope
Filename:="\\C:\myfiles\SOMEFILENAMETHATCHANGESeachmonth.xls"

Is it possible to have excel do this automatically or am I stuck wit
having to go in to VBA and edit the code each month
 
Try something like this

Sub test()
Dim Myvar As Range
Set Myvar = Sheets("sheet1").Range("A1")
Workbooks.Open Filename:="\\Jelle\shareddocs\" & Myvar & ".xls"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top