I am using msoFileDialogFolderPicker to get the folder path and folder name by browsing and selecting the required folder, where a dialog box will open and the user have to select the folder by clicking OK in the dialog box.
If a folder is selected and OK is clicked, the full folder path is stored in the variable Folderpth. If cancel is clicked, the variable Folderpth will be blank.
My issue is, if the user clicks OK even without selecting the folder, that particular directory path is getting stored in the variable Folderpth .
Here is the code i am using,
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
With diaFolder
diaFolder.Title = "Select the source folder"
diaFolder.AllowMultiSelect = False
If diaFolder.Show = -1 Then
Folderpth = .SelectedItems.Item(1)
splitting = Split(Folderpth, "\", 9)
counter = UBound(splitting)
foldername = splitting(counter)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Folderpth)
Else
MsgBox "Please select the Source folder"
Folderpth = ""
Exit Sub
End If
End With
If the user browse to a folder, where its subfolder is his required folder, but without selecting the required folder if he clicks ok, the path captured will be incorrect. I want to over come capturing the folder path without selecting it.
Is it possible
if Folderpth = Application.ActiveWorkbook.path then Folderpth = Nothing
or something like that. - Christofer WebermsoFileDialogFolderPicker
, store the initital path in a variable. When the user click ok, match it with the new path. If the paths are same then inform user that the path is same and would he like to continue? Simple as that - Siddharth RoutWith diaFolder
,diaFolder.Title
should probably just be.Title
, and same for the others. - Christofer Weber