Thanks Greg. This has been a great help to me. I can see what you did and it's easy to follow.
Following on, using your advice, I declared another variable BMcnt and used this as a counter to add on to the bookmark name. This means if I have four bookmarks, I can consecutively cycle through each and change the text in each one. This may not sound very productive but helps me understand For Next loops.
I see now that instead of just cycling through, by using IF statements I can write predetermined text to a document via a bookmark, based on a condition.
Can you explain the relevance of 'lbl_Exit:' towards the end of the routine?
Sub BookmarkUpdate()
Dim oBMRng As Range
Dim lngIndex As Long
Dim BMcnt As Long
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
End Sub
|