I'm using the below code to bring up the file dialog box so the user can select a file path to save a file.
What I want to do is stop an error from occuring when the user clicks the 'Cancel' button in the dialog box. Currently when you click 'Cancel', it comes up with 'Run-time error '5': Invalid procedure call or argument' and highlights the last line in the code below. Does anyone know how I can fix this?
What I want to do is stop an error from occuring when the user clicks the 'Cancel' button in the dialog box. Currently when you click 'Cancel', it comes up with 'Run-time error '5': Invalid procedure call or argument' and highlights the last line in the code below. Does anyone know how I can fix this?
Code:
Dim mySaveLocation As String
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
dlg.AllowMultiSelect = False
dlg.Show
mySaveLocation = dlg.SelectedItems.Item(1)