The following code can be used to display an OpenFile dialog box.
This allows the user to select the workbook to be processed.
Dim
fileToOpen As Variant
Dim
wkb As Workbook
fileToOpen = Application.
GetOpenFileName __
(FileFilter:="microsoft excel files (*.xls), *.xls", __
Title:="Get File", MultiSelect:=True)
If
fileToOpen <> false then
Application.Workbooks.Open fileToOpen
Set wkb = ActiveWorkbook
mname = DIR(filex)
wkb.SaveAs filename:=hpath + mname
End if
Application.GetOpenFileName will display an open dialog box
fileToOpen is a variable that will contain the name and path of the selected file.
If a file was not selected,
fileToOpen will be false.
DIR(fileToOpen) will return the file name portion of the file in filex.
FileFilters describe which files are displayed in the Open File dialog
Examples of Filter Statements
FileFilter:="Microsoft Excel Files (*.xls), *.xls"
FileFilter:="Text Files (*.txt), *.txt"
FileFilter:="Add-In Files(*.xla), *.xla"
FileFilter:="Text Files (*.txt), *.txt", Add-In Files(*.xla), *.xla"
The above will list both filters in the drop-down box
FileFilter:="Visual Basic Files(*.bas; *.txt), *.bas; *.txt"
Semi-colons separate multiple file types for a single filter type
Copyright © 2006-2019, LQSystems,Inc. All rights reserved.