Thread: [Solved] Proper use of lbl_Exit:
View Single Post
 
Old 11-16-2022, 10:31 AM
BrianHoard BrianHoard is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default Proper use of lbl_Exit:

As our small team learns VBA, we get a lot of info from the folks on this forum and their websites. I like to understand every line of code, and not blindly copy/paste from the internet.

As I review several of our scripts, I keep seeing this "lbl_Exit:" From my Windows cmd scripting, this looks like it may be the target for a GOTO command? But I'm seeing it just listed in the script with nothing else pointing to it. Which I'm guessing will just run the commands under this label when it appears in the script.

Can someone explain what this is about, or where I can learn more about it, and even if I need it at all?

Here's is one of several similar scripts we've created that uses lbl_Exit: But nothing in the script calling it.

I'm guessing setting a variable to Nothing clears it, which seems like a good thing to do. Not sure if that is necessary, as Exit Sub and End Sub would probably do that anyways, right?

Code:
Sub bhh_removeCrossRefs()
  ' Do what Ctrl shift F9 does, removing cross-references.
  
  Dim i as Integer
  Dim oStory As Range
  For Each oStory In ActiveDocument.StoryRanges
    For i = oStory.Fields.Count To 1 Step -1
      If oStory.Fields(i).Type = wdFieldNoteRef Then
        Debug.Print (oStory.Fields(i).Type)
        oStory.Fields(i).Unlink
      End If
    Next i
  Next oStory
  
  lbl_Exit:
    Set oStory = Nothing
    Exit Sub
    
End Sub ' bhh_removeCrossRefs
Reply With Quote