Does Stop in a sub-procedure always persist to the caller?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
1,263
Office Version
365, 2016, 2007
Platform
Windows
If I write a general-purpose error handler that, among other things, executes a Stop statement under certain conditions, can I be assured that it will persist past the termination of the sub-function and allow me to continue stepping through the caller using F8?

I have tested it and it seems to work, but I'd like to hear from anyone who knows for sure that it does or if there are conditions where it does not. The caller and subroutine are in the same module.

Thanks
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Kyle123

Well-known Member
Joined
Jan 24, 2012
Messages
2,699
Could you post some code illustrating your scenario? I'm struggling to get my head around your question
 

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
1,263
Office Version
365, 2016, 2007
Platform
Windows
Could you post some code illustrating your scenario? I'm struggling to get my head around your question
Sure.

Code:
Public Function MainFn(. . .)
 . . .
If (some error condition) then
  Call ErrorHandler(. . .)
  MainFn = CVErr(xlErrValue): Exit Function
End If
 . . .
End Function


Public Function ErrorHandler(. . .)
. . .
Dim Button as Long
Button = MsgBox(". . .", vbYesNo, . . .)
If Button = vbYes then Stop
 . . .
End Function
The error handler puts up a MsgBox asking the user whether to issue a Stop so some debugging can take place.

My question is, "Will the Stop statement in ErrorHandler still be in effect when it returns control to MainFn? That is, after the Stop interrupts execution, can I step through the code using F8 for the rest of ErrorHandler and back into MainFn?

I've tested it and it seems to work, but VBA is quirky, so I wanted to be sure it would always work and that there is not a better way.

Clearer?
 

Watch MrExcel Video

Forum statistics

Threads
1,095,381
Messages
5,444,124
Members
405,269
Latest member
Kjtakke

This Week's Hot Topics

Top