PDA

View Full Version : Colour coding bookmarks



KyleN
03-15-2012, 06:45 AM
Hi, I've been working on a letterhead template, which is pretty much good to go - but there's a little something I need some help/advice with.

A bit of background / The way it works:
The user opens the letterhead template and a form automatically launches for user input.
They are asked to type their name, job title etc. and there are option buttons which will will place the correct company name and address into a particular bookmark...

Everything up to here is great! But... What I'd like is for the bookmark font colour to change, depending on what it says.

7660

Any help will be uberly appreciated! :biggrin:
(And no, uberly isn't a word :whistle:)

gmaxey
03-15-2012, 04:01 PM
Bookmarks are named ranges. You define the name (e.g., a bookmark that binds a persons name might be named bmName) and the range is defined by what the bookmark bounds:

Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim oBM As Bookmark
Set oBM = ActiveDocument.Bookmarks("bmName")
Select Case oBM.Range.Text
Case Is = "Kyle Nelson"
oBM.Range.Shading.BackgroundPatternColor = RGB(194, 0, 74)
Case Else
oBM.Range.Shading.BackgroundPatternColor = RGB(255, 0, 0)
End Select
End Sub

fumei
03-15-2012, 05:15 PM
And if you have multiple bookmarks (and you do) and you want to:

depending on what it says.

then you will have to loop through them all testing for "what it says". Going for a specific text - e.g. Kyle Nelson - in a specific bookmark, is easy. Basically it is one test, as in the example Greg posted.

Do you need to find a lot?