Application.GetOpenFileName


Excel - (File > Open) dialog box

SS
This should not be used but is still available in backwards compatibility.



Application.GetOpenFileName

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, _ 
                           FilterIndex, _
                           Title, _
                           ButtonText, _
                           MultiSelect)

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.
Title -
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")
End If


Return Value = Variant

The value this function retuns must be assigned to a variant.

Sub DisplayFileOpen 
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, _
                                        FilterIndex:=1, _
                                        Title:="Open a New or an Old File", _
                                        MultiSelect:=False)

'did you press Cancel?
   If vaFile <> False Then
      MsgBox "You want to open " & vaFile
   End If
End Sub


0161930 - How to Use the GetOpenFilename Method
0153722 - GetOpenFilename Method Is Different in MS Excel for Win 95 and MS Excel 97
0141574 - How to Create a Macro That Opens Multiple Selected Files


Word

Does not exist


PowerPoint

Does not exist



© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext