Code:
Function dialogFolderBrowse() As String
Dim fp As FileDialog
Dim vrtSelectedItem As Variant
Dim VarX As String
'this next line is an optional warning to the user so they know what is about to happen
'MsgBox "LOCATE THE DESIRED FOLDER!!", vbOKOnly
'Create a FileDialog object as a Folder Picker dialog box.
Set fp = Application.FileDialog(msoFileDialogFolderPicker) ' can use msoFileDialogFilePicker for filenames
fp.AllowMultiSelect = True
If fp.Show = -1 Then
For Each vrtSelectedItem In fp.SelectedItems
VarX = vrtSelectedItem
'vrtSelectedItem is a String that contains the path of each selected item.
Next vrtSelectedItem
End If
dialogFolderBrowse = VarX
End Function
THE UPPER code is to locate the user desired folder path and name in order to do further process. However, my problem is that no matter I press <OK> or <Cancel> option in the normal MS Folder dialog box, the process still going on. Is that I miss some on error or on exit code??
Thanks a lot!! My idea is that when user press <OK>, the process goes on and when press <Cancel>, no process will be done!!