using Path to open a specific file

sbp1975

New Member
Joined
May 18, 2018
Messages
3
Greetings knowledgeable sages,
I would like to create additional Excel workbooks in a folder/directory where a master workbook is located (or potentially one level up in the directory hierarchy). I have various template files, so want the user be able to select the specific file to spawn from, but do not want the user to have to navigate through the entire path. (Or another way to do this would just be to have all the templates in a set directory, and have the user pick which one to use, ideally from an Open File dialog...)
It does not seem like there is an option in Application.GetOpenFilename to use the path. So is there another function that would open a dialog in the proper directory for the user to select the file from which to open a new file?

Code:
Dim FolderPathName As String    ' the path for the current Master Data Sheet
Dim TemplateToUse As Variant  ' the file that the user selects
Dim nwb As Workbook  ' new Workbook to modify, from the selected Template

' find the latest Prototype to use
FolderPathName = ActiveWorkbook.Path
TemplateToUse = Application.GetOpenFilename()  ' any way to get this to go to the FolderPathName?
If TemplateToUse = False Then Exit Sub
Set nwb = Workbooks.Open(TemplateToUse)
' do stuff to modify nwb and save off as a new file name in the same path as the master workbook
TemplateToUse.Close savechanges:=False
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try like this:

Code:
FolderPathName = ActiveWorkbook.Path
ChDrive Left(FolderPathName, 1)
ChDir FolderPathName
TemplateToUse = Application.GetOpenFilename()

WBD
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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