Get the selected file name in a file open dialog : GetOpenFilename « File Path « VBA / Excel / Access / Word






Get the selected file name in a file open dialog

 

Sub GetImportFileName()
    Filt = "Text Files (*.txt),*.txt," & _
           "Lotus Files (*.prn),*.prn," & _
           "Comma Separated Files (*.csv),*.csv," & _
           "ASCII Files (*.asc),*.asc," & _
           "All Files (*.*),*.*"

    FilterIndex = 5
    Filename = Application.GetOpenFilename (FileFilter:=Filt, FilterIndex:=FilterIndex, Title:="Select a File to Import")
    If Filename = False Then
        MsgBox "No file was selected."
        Exit Sub
    End If
    Debug.Print Filename
End Sub

 








Related examples in the same category

1.Selecting multiple files
2.Application.GetOpenFilename
3.Load excel file
4.Use filter in Open file dialog