Pages

Monday, August 22, 2011

Show folder name picker dialog box using VBA

If you want open the folder picker dialog box and then save the path of the folder for further use. Try this macro


Sub choose_folder()

    Dim fldname As String
    Dim fd As FileDialog, fl As Variant
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
        .AllowMultiSelect = False
        .Title = "Please select the folder"
        .Show
    End With
    
    For Each fl In fd.SelectedItems
        fldname = fl
    Next
    
    If fldname = "" Then
        MsgBox "Folder Not selected", vbInformation, "Note:"
    Else
        MsgBox fldname & "\"
    End If
    
End Sub

No comments:

Post a Comment