Samadhan Gaikwad
Member
Hi,
I have a code which allow user to select folder (dir path) and add to one of the cell.
And there are some macros that run ahead.
But problem is when I do not select any folder and hit Cancel button, yet further code is executed. Also would like to show msg box to user to let know to select folder, if he did not select any.
I have a code which allow user to select folder (dir path) and add to one of the cell.
And there are some macros that run ahead.
But problem is when I do not select any folder and hit Cancel button, yet further code is executed. Also would like to show msg box to user to let know to select folder, if he did not select any.
Code:
Function GetFolder() As String
Dim fldr As FileDialog
Dim ParentFolderName As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder to download PRdata into"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
ParentFolderName = .SelectedItems(1)
Sheets("Download_PRdata1").Range("A28").Value = ParentFolderName
End With
NextCode:
GetFolder = ParentFolderName
Set fldr = Nothing
On Error Resume Next
End Function
Last edited: