Formatting Field Code Text (Cross References and Bookmarks)

T

Tamara

Is there a way to automate or use macros to globally reformat the text
appearing in cross references and bookmarks?

For example, this macro globally reformats field code text to be lowercase:

Sub FieldRefChanges1()
On Error Resume Next
Dim oStoryRng As Range
Dim oFld As Field

For Each oStoryRng In ActiveDocument.StoryRanges
For Each oFld In oStoryRng.Fields
If oFld.Type = wdFieldRef And oFld.Result.Words.Count <= 2 Then
'add format switch with lowercase option to field codes
oFld.Code.Text = oFld.Code.Text & "\* lower "
'updates the field results to display the new format
oFld.Update
End If
Next oFld
Next oStoryRng
End Sub


I'd like to globally reformat cross references and bookmarks in a document
so that they appear with blue text instead of black. See page 3 of
ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_doc_sraidmr_10.01_install-user-guide.pdf
as an example. Is it possible to use charformat or some other formatting
switch?

Any insight would be appreciated.

Thank you,
 
S

Stefan Blom

If you add the \* CHARFORMAT switch, you can then format the REF field code
in blue. Something like this:

Sub FieldRefChanges2()
On Error Resume Next
Dim oStoryRng As Range
Dim oFld As Field

For Each oStoryRng In ActiveDocument.StoryRanges
For Each oFld In oStoryRng.Fields
If oFld.Type = wdFieldRef And oFld.Result.Words.Count <= 2 Then
'add charformat switch:
oFld.Code.Text = oFld.Code.Text & "\* CHARFORMAT "
oFld.Code.Font.Color = wdColorBlue
'updates the field results to display the new format
oFld.Update
End If
Next oFld
Next oStoryRng
End Sub
 
T

Tamara

Thanks. This worked!

Stefan Blom said:
If you add the \* CHARFORMAT switch, you can then format the REF field code
in blue. Something like this:

Sub FieldRefChanges2()
On Error Resume Next
Dim oStoryRng As Range
Dim oFld As Field

For Each oStoryRng In ActiveDocument.StoryRanges
For Each oFld In oStoryRng.Fields
If oFld.Type = wdFieldRef And oFld.Result.Words.Count <= 2 Then
'add charformat switch:
oFld.Code.Text = oFld.Code.Text & "\* CHARFORMAT "
oFld.Code.Font.Color = wdColorBlue
'updates the field results to display the new format
oFld.Update
End If
Next oFld
Next oStoryRng
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top