Thread: [Solved] Proper use of lbl_Exit:
View Single Post
 
Old 11-17-2022, 02:28 PM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Brian,


I do that a lot and I've posted a lot of code here with the lbl_Exit statement.


I use phrase express and when I type sam in a VB code pane, I get:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey

lbl_Exit:
Exit Sub
End SUb


When I am reviewing other people's (often to fix), I usually add the lbl_Exit statement as a flag to remind me that I've already looked at that procedure.


Often, and in those cases, it has no functional value and only there as style. Some folks from the old school used to practice never let a procedure run to the End Sub line. Exit first. Why, I don't know but it just became as habit for me.

To make is useful, I would do something like this:

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng as Range
Set oRng = ActiveDocument.range
On Error GoTo Err_Handler
Err.Raise 6
lbl_Exit:
Set oRng = Nothing
Exit Sub
Err_Handler:
Msgbox Err.Number & " " & Err.Description
Resume lbl_Exit
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote