using variables in a path

robertdseals

Active Member
Joined
May 14, 2008
Messages
333
Office Version
  1. 2010
Platform
  1. Windows
Hello all,
I'm trying to use variables in a path name.

Dim MyFolder As String, MyFile As String
Dim MyCasino As String
Dim MyMonth As String
MyCasino = InputBox("which casino i.e. MR")
MyMonth = InputBox("which month i.e. 06")


MyFolder = "M:\Division of Gaming\GPI\MyCasino\2015\MyMonth"
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile

Part of the path to the folder includes MR, JP or BA and the month can be 01, 02, 03...
the formula ="M:\Division of Gaming\GPI\MR\2015\05" works, but not when I try to substitute MR with MyCasino or the 05 with "MyMonth".
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
For example,

Code:
MyFolder = "M:\Division of Gaming\GPI\" & MyCasino & "\2015\MyMonth"
 
Upvote 0
Brilliant! Had to modify it a bit, but Grand Idea!
Thanks,
MyFolder = "M:\Division of Gaming\GPI\" & MyCasino & "\2015\" & MyMonth
 
Upvote 0

Forum statistics

Threads
1,207,424
Messages
6,078,448
Members
446,339
Latest member
keogata

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