View Single Post
 
Old 08-23-2020, 05:36 AM
gmaxey gmaxey is offline Windows 10 Office 2016
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

Red,


There you go.


In the example I provided, lbl_Exit really has no relevance and it is there only as part of my standard coding style (I never like to hit the End Sub line) as an exit point. In practice, it serves as a resume label in error handling. Consider one of the bookmarks is missing:


Code:
Sub BookmarkUpdate()
Dim oBMRng As Range
Dim lngIndex As Long
Dim BMcnt As Long
  On Error GoTo ErrHandler
  For BMcnt = 1 To 4
    For lngIndex = 1 To 4
      Set oBMRng = ActiveDocument.Bookmarks("MyBookmark" & BMcnt).Range
      Select Case lngIndex
        Case 1: oBMRng.Text = "First"
        Case 2: oBMRng.Text = "Second"
        Case 3: oBMRng.Text = "Third"
        Case 4: oBMRng.Text = ""
      End Select
      'Re-insert the bookmark
      ActiveDocument.Bookmarks.Add "MyBookmark" & BMcnt, oBMRng
    Next lngIndex
  Next BMcnt
lbl_Exit:
  Exit Sub
ErrHandler:
  MsgBox "Bookmark MyBookmark " & BMcnt & " does not exist."
  Resume lbl_Exit
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote