I'm having some trouble showing a messagebox if the user presses OK but doesn't select a folder using msoFileDialogFolderPicker. Can someone help point me in the right direction?
Sub BrowseFolderDialog()
Dim selectedItem As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = ""
If .Show = -1 Then
If .SelectedItems.Count > 0 Then
selectedItem = .SelectedItems(1)
End If
MsgBox CStr(.SelectedItems(1))
MsgBox selectedItem
If Not InStr(selectedItem , ":\") Then
MsgBox "You didn't select a folder. The procedure has been canceled."
SaveSettings.OBFilePathDefault = True
Exit Sub
End If
If .SelectedItems.Count > 0 Then
selectedItem = .SelectedItems(1)
SaveSettings.TextBoxCustomPath.Text = selectedItem
Sheets("Back").Range("J2").Value = selectedItem
End If
Else
MsgBox "Canceled"
End If
End With
End Sub
The 2 MsgBox's I've added show the same string, yet the If Not InStr line returns true regardless if ":\" is in the string or not. Any advice or other methods you can suggest?
Bookmarks