Pages

Monday, August 22, 2011

Show file name picker dialog box using VBA

If you want open the file picker dialog box and save the full path of file in a variable . Try this macro  -




Sub choose_file()

    Dim flname As String
    Dim fd As FileDialog, fl As Variant
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .AllowMultiSelect = False
        .Title = "Please choose the file"
        .Filters.Add "Excel Files", "*.xls*", 1
        .Show
    End With
    
    For Each fl In fd.SelectedItems
        flname = fl
    Next
    
    If flname = "" Then
        MsgBox "File Not selected", vbInformation, "Note:"
    Else
        MsgBox flname
    End If


End Sub

No comments:

Post a Comment