• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need Help With Editing On-Error Procedure

ham123

Member
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.

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! :)
 

Attachments

  • Capture.JPG
    Capture.JPG
    17.9 KB · Views: 1
Change
If sFileName <> False And Dir(sFileName, vbNormal) <> "" Then

To:
If sFileName <> False And sFileName <> "" Then
 
Back
Top