View Single Post
 
Old 08-22-2020, 03:18 PM
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

Good to see you wan to learn. When you have rather convoluted If ... Else ... End If conditions, it is often easier to use Select Case. Also, if you are going to declare one variable, you might as well declare all.


Code:
Sub BookmarkUpdate()
Dim oBMRng As Range
Dim lngIndex As Long
  For lngIndex = 1 To 4
    Set oBMRng = ActiveDocument.Bookmarks("MyBookmark").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", oBMRng
  Next lngIndex
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote