Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 08-23-2020, 01:55 AM
RedZed1100 RedZed1100 is offline Using If Then with Bookmarks to specify text Windows 10 Using If Then with Bookmarks to specify text Office 2016
Novice
Using If Then with Bookmarks to specify text
 
Join Date: Aug 2020
Location: England
Posts: 8
RedZed1100 is on a distinguished road
Default

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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing text held in all bookmarks THH4929 Word VBA 6 06-02-2018 04:29 AM
Using If Then with Bookmarks to specify text How to insert bookmarks for content or Text of ContentControl lvganesh Word VBA 5 12-12-2017 11:27 PM
Using If Then with Bookmarks to specify text Deleting only all bookmarks contents not the bookmarks 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
Using If Then with Bookmarks to specify text Form updating Bookmarks - writes to the bookmarks multiple times PeterPlys Word VBA 13 01-14-2015 06:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft