File Path Variable

Braunschweiger

Board Regular
Joined
Feb 19, 2014
Messages
104
I have a workbook that processes data and puts it into a usable format for people in my department. The workbook pulls data from about 12 other workbooks. Currently, my script points to a location on my hard drive. I'd like the file location to be a variable so...I can hand this workbook off to other people so...they can run the report themselves. I'd like them to be able to input the file location on their PC...into the script. So, file location is a variable and could change but...the file names of the 12 feeder files will not change. Below is an example of what I'm currently using:

Code:
Dim wkb As Workbook
Dim sht As Worksheet
Set wkb = Workbooks.Open("C:\Users\David\Documents\HUD WORK\Portfolio Snapshot\Dumps\dbo_active_financing.xlsx")
Set sht = wkb.Sheets("dbo_active_financing")
sht.Activate


Dim wkb As Workbook
Dim sht As Worksheet
Set wkb = Workbooks.Open("C:\Users\David\Documents\HUD WORK\Portfolio Snapshot\Dumps\dbo_active_financing_participant.xlsx")
Set sht = wkb.Sheets("dbo_active_financing_participan")
sht.Activate

The first script points to a location on my PC and opens a file named "dbo_active_financing". The second script does the same thing except...opens "dbo_active_financing_participan" rather than..."dbo_active_financing". I want the user to be able to change the bold, blue part of the script below.

C:\Users\David\Documents\HUD WORK\Portfolio Snapshot\Dumps\dbo_active_financing.xlsx
C:\Users\David\Documents\HUD WORK\Portfolio Snapshot\Dumps\dbo_active_financing_participant.xlsx"

As always...very grateful for every ones help!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
Code:
Dim wkb As Workbook
Dim sht As Worksheet
Dim Pth As String
Pth = "C:\Users\David\Documents\HUD WORK\Portfolio Snapshot\Dumps\"
Set wkb = Workbooks.Open(Pth & "dbo_active_financing.xlsx")
Set sht = wkb.Sheets("dbo_active_financing")
sht.Activate
Or you could use
Code:
Pth = Environ("userprofile") & "\Documents\HUD WORK\Portfolio Snapshot\Dumps\"
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,048
Members
452,542
Latest member
Bricklin

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