Im using Application.FileDialog(msoFileDialogFolderPicker) to choose a folder. This is executed by using a button in userform. However before the user choose the folder a new sheet will be created. Then the open file dialog [Application.FileDialog(msoFileDialogFolderPicker)] will pop up.
Function SelectFolder(Optional msg As String) As String
Dim diaFolder As FileDialog
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Title = msg
diaFolder.Show
On Error Resume Next
SelectFolder = diaFolder.SelectedItems(1)
On Error GoTo 0
Set diaFolder = Nothing
End Function
The problem arises when user decided to cancel to choose the folder. When this happen, the newly created sheet should be deleted. I tried to use error handler but now luck.
ErrorHandler:
If SheetExists("MS") Then Application.Run "DeleteSheet.deleteSh1"
If SheetExists("MS2") Then Application.Run "DeleteSheet.deleteSh2"
If SheetExists("MT") Then Application.Run "DeleteSheet.deleteSh3"
Application.Run "HideSheets.hideSh"
Resume Next
Exit Sub
Hope you guys can give some idea on this.
On Error GoTo 0you should useOn Error GoTo ErrorHandler(GoTo 0 Disables enabled error handler in the current procedure and resets it to Nothing. - [link]msdn.microsoft.com/en-us/library/5hsw66as.aspx ) Or if your ErrorHandler is in a separate Sub, call it from the error section of your SelectFolder Function