Re: Globally Changing Field Font Color in Word

Subject: Re: Globally Changing Field Font Color in Word
From: technical -at- theverbalist -dot- com
To: "TECHWR-L" <techwr-l -at- lists -dot- raycomm -dot- com>
Date: Thu, 29 Apr 2004 08:42:09 -0600


> Anyone know if there is a way to globally change the field code font color in Word 2002? I have a lot of cross-references such as, "see Figure 4," and they are all in automatic (black). The requirement is to have all cross-references in blue. I can change them individually by selecting, then formatting font but there are at least a hundred cross-references in this biggie doc. There MUST be a way to change them all at once. Any X-perts out there?
>

I replied to Tom off-list, but then I thought that someone else might
benfit from the answer. That, and also, I wanted to show off. So here's my
answer to Tom...

I had exactly that problem, but my friend Alan, crack macro creator,
created a macro that solved the problem for me.

Here is the macro and the instructions for pasting the macro into your
templates (thanks to the WORD MVP site for those). In my docs, the style
to add a colour to a field is "Crossref"; you can change that to whatever
your style name is.

To add a macro to your docs:

Select Tools + Macro + Macros, where it says Macros in, select the
template you want to store the macro in; where it says Macro name, type a
name, and click Create. You will see something like

Sub MyMacroName()
'
' MyMacroName Macro
' Macro created 03/08/00 by Me'

End Sub

You can safely delete the lines in the middle, and add your own code, or
paste in the code sent to you by others. Then select File + Save to save
the macro in your template.

You can run the macro while you are still in the macro-editing window
(normally referred to as the VB Editor or VBE) by pressing F5. You can
also size the VBE and the Word window on your screen so you can see them
both at once, and step through the macro one line at a time, in order to
see what it does, by pressing F8.

To run the macro from within Word, you can press Alt+F8 (or select Tools +
Macro + Macros), find the macro in the list, and press Run.

But if you are likely to want to run the macro regularly, you can assign
it to a keyboard shortcut, or to a toolbar, or a menu.

And the macro code I used is:

Sub AddMergeFormatToDocument()
'
' Add \* mergeformat to ref and pageref fields
'
' show code view
ActiveWindow.View.ShowFieldCodes = False

' go to the beginning of the document
Selection.HomeKey Unit:=wdStory

' find fields
Dim aField As Field
Dim aRange As Range
For Each aField In ActiveDocument.Fields
' if the field is ref or pageref
If aField.Type = wdFieldRef Or aField.Type = wdFieldPageRef Then
Set aRange = aField.Code
If InStr(1, aRange.Text, "mergeformat", vbTextCompare) = 0 And
_
InStr(1, aRange.Text, "MERGEFORMAT", vbTextCompare) = 0 And
_
InStr(1, aRange.Text, "Mergeformat", vbTextCompare) = 0
Then
aRange.Text = aRange.Text & " \* mergeformat "
aField.Select
Selection.Style = "Crossref"
End If
End If
Next
End Sub

I saved it in the Normal template, which makes it available in any
template you're using.

Then, when I've finished with a doc and created the TOC, I run the macro
and it changes the font colour of the xref fields and the page numbers in
the TOC to blue.

Hope this works for you,
Mandy


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ROBOHELP X5 - ALL NEW VERSION. Now with Word 2003 support, Content
Management, Multi-Author support, PDF and XML support and much more!

Now is the best time to buy - special end of month promos, including:
$100 mail-in rebate; Free online orientation on content management
functionality; Huge savings on support and future product releases;
PLUS Great discounts on RoboHelp training. OFFER EXPIRES April 30th!
Call 1-800-358-9370 or visit: http://www.ehelp.com/techwr-l

---
You are currently subscribed to techwr-l as:
archiver -at- techwr-l -dot- com
To unsubscribe send a blank email to leave-techwr-l-obscured -at- lists -dot- raycomm -dot- com
Send administrative questions to ejray -at- raycomm -dot- com -dot- Visit
http://www.raycomm.com/techwhirl/ for more resources and info.



Previous by Author: RE: Don't say what you CANNOT do in documents
Next by Author: Re: FrameMaker: Problem with cross references
Previous by Thread: Globally Changing Field Font Color in Word
Next by Thread: Manager's survey respondents needed


What this post helpful? Share it with friends and colleagues:


Sponsored Ads