Greetings experts,
I have this code and what it does is that it will open the file explorer and the user has to select another Excel file which has a userform that they want to use on the Excel file where they run this code.
However, when I press cancel on the file explorer, a "type mismatch" error will appear. I do not want the user to see this. If they press cancel on the file explorer, the error should not be shown.
Any help is much appreciated!
I have this code and what it does is that it will open the file explorer and the user has to select another Excel file which has a userform that they want to use on the Excel file where they run this code.
Code:
Sub OpenFile()
Dim sFileName As Variant
sFileName = Application.GetOpenFilename("Excel Files (*.xl*), *.xl*")
If sFileName <> False And Dir(sFileName, vbNormal) <> "" Then
Call ShowForm(sFileName)
End If
End Sub
Sub ShowForm(ByVal FilePath As String)
'Please add your error handlers
Application.Run "'" & FilePath & "'!ShowForm"
On Error GoTo ErrHandle
Application.Run "'" & FilePath & "'!ShowForm"
Exit Sub
ErrHandle:
MsgBox "You canceled the process!"
End Sub
However, when I press cancel on the file explorer, a "type mismatch" error will appear. I do not want the user to see this. If they press cancel on the file explorer, the error should not be shown.
Any help is much appreciated!