Tuesday 20 March 2018

Ask user to select a folder during the macro VBA | How to get pop up window to select a folder in VBA


Ask user to select a folder during the macro VBA | How to get pop up window to select a folder in VBA


Function GetFolder(StrPath As String) As String
Dim Fldr As FileDialog
Set Fldr = Application.FileDialog(msoFileDialogFolderPicker)
With Fldr
    .Title = "Select a Folder"
    .AllowMultiSelect = False
    .InitialFileName = StrPath
    If .Show <> -1 Then
    MsgBox "You Should select a Folder!", , "Warning": GetFolder (StrPath)
    End If
    GetFolder = .SelectedItems(1)
End With
Set Fldr = Nothing
End Function

No comments:

Post a Comment