Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling disabled after Application.Run?

Status
Not open for further replies.

soaphope

Technical User
Jan 17, 2011
1
US
It looks like Application.Run destroys the error handling chain.

Calling Test1 causes the message box to display. Calling Test2 does not. Is this a bug?

My application uses extensive use of Application.Run to simulate "virtual" functions. Is there some way to overcome this apparent limitation of the error handling mechanism in VBA?

Code:
Public Sub Test1()
  On Error GoTo doErr
  MakeErr
  
doErr:
  MsgBox ("here")
End Sub

Public Sub Test2()
  On Error GoTo doErr
  Application.Run "MakeErr"
  
doErr:
  MsgBox ("here")
End Sub

Public Sub MakeErr()
  Err.Raise 1
End Sub
 
If you look at the stack when debugging, the non-vba code info appears in Test2. You can try instead:
Code:
Public Sub Test3()
On Error GoTo doErr
CallByName ThisWorkbook.VBProject, "MakeErr", VbMethod

doErr:
MsgBox ("here")
End Sub

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top