This should not be used but is still available for backwards compatibility.
Excel - (File > Open > Browse) dialog box
Can be used to obtain a valid filename and its full path.
This method displays the Open dialog box but will not actually open the file.
This method will return a string value specifying the path and filename that was selected.
sFullPath = Application.GetOpenFileName(FileFilter, _
FileFilter - This determines the types of files that will be displayed in the Files Of Type drop-down list. This argument consists of pairs of the file filter display text followed by the wildcard file filter specification. Each pair seperated by commas. The default is "User (*.*), *.*"
FilterIndex - This specifies which file filter is the default. Not required if there is only one filter provided.
ButtonText - This argument is not used in Excel for Windows.
MultiSelect - Determines if the user can select multiple files. If you allow multiple files to be selected you can use the IsArray() function to check if multiple files were selected.
All the arguments are optional.
sFullPath = Application.GetOpenFileName()
When you want to filter the choice to specific file extensions you must use the following format: "description,*.extension"
The following line of code will display a dialog box allowing you to select an XML file.
sFullPath = Application.GetOpenFileName(FileFilter:="Excel Files (*.xlsx),*.xlsx", _
Title:="Please select an Excel file")
If Len(sFullPath) = 0 Then
MsgBox("No file selected")
Return Value = Variant
The value this function retuns must be assigned to a variant.
Dim sFilter As String
Dim vaFile As Variant
'build a filter list
'if you omit the space before the first comma excel will not display the pattern, (*.New)
sFilter = "New Files (*New) ,*.new," & _
"Old Files (*Old) ,*.old," _
"All Files (*.*) ,*.*"
'display the file open dialog putting the result in a variant
vaFile = Application.GetOpenFileName(FileFilter:=sFilter, _
Title:="Open a New or an Old File", _
'did you press Cancel?
If vaFile <> False Then
MsgBox "You want to open " & vaFile
Does not exist
Does not exist
© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext