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
    End With
    For Each fl In fd.SelectedItems
        flname = fl
    If flname = "" Then
        MsgBox "File Not selected", vbInformation, "Note:"
        MsgBox flname
    End If

End Sub

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...