Thursday 22 March 2018

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


Ask user to select a file during the macro VBA :


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

No comments:

Post a Comment