Use filter in Open file dialog : GetOpenFilename « File Path « VBA / Excel / Access / Word






Use filter in Open file dialog

 

Sub GetImportFileName2()
    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",MultiSelect:=True)
    If Not IsArray(Filename) Then
        MsgBox "No file was selected."
        Exit Sub
    End If
    For i = LBound(Filename) To UBound(Filename)
        Debug.Print Filename(i)
    Next i
End Sub

 








Related examples in the same category

1.Selecting multiple files
2.Application.GetOpenFilename
3.Load excel file
4.Get the selected file name in a file open dialog