![]() |
|
#1
|
|||
|
|||
![]()
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 |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replacing text held in all bookmarks | THH4929 | Word VBA | 6 | 06-02-2018 04:29 AM |
![]() |
lvganesh | Word VBA | 5 | 12-12-2017 11:27 PM |
![]() |
adilprodigy | Word VBA | 1 | 10-11-2017 01:31 PM |
Macro to hide/unhide text to call variable bookmarks | Dr. Z | Word VBA | 2 | 05-27-2017 08:20 PM |
![]() |
PeterPlys | Word VBA | 13 | 01-14-2015 06:41 AM |