View Single Post
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Dave[_10_] Dave[_10_] is offline
external usenet poster
 
Posts: 9
Default How to maintain the formatting of a Cross Reference

Thanks Graham for all the help, finally got the formatting of references
sorted out.

"Graham Mayor" wrote in message
...
The macro has no effect on existing cross references. If you want to
change existing cross references to display in blue, you need a different
macro. In fact you can insert your references normally and use this macro
to update them all at once.

Sub ChangeFieldContent()
Dim strCodes As String
Dim iFld As Integer
Dim strFind As String
Dim strRepl As String
Selection.HomeKey
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldRef Then
If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"\* MERGEFORMAT", "\* CHARFORMAT")
End If
If InStr(1, UCase(.Code), "CHARFORMAT") = 0 Then
.Code.Text = .Code.Text & " \* CHARFORMAT "
End If
.Code.Font.Color = wdColorBlue
.Update
End If
End With
Next iFld
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Dave wrote:
Thanks for that Graham, seems like I made a mistake some where. It
works fine now.

I just noticed something, the formatting for existing cross
references does not change. Do I have to manually recreate the links
or is it supposed to change existing link formats also?

Thanks
Dave

"Graham Mayor" wrote in message
...
Did you copy the whole thing - particularly the preceding line? It
works for me in Word 2003.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Dave wrote:
Thanks for the reply Graham

I tried the code you gave me and it keeps giving a syntax error for
the following lines

With oRange.Fields(iFld)
.Code.Text = .Code.Text & " \* CHARFORMAT "
.Update
End With

Any idea why?

Thanks
Dave

"Graham Mayor" wrote in message
...
When you update the field it re-reads the referenced item and
resets it as it was originally. To get around this you need to add
a charformat switch to the field. The dialog has no option to do
this, but you can add it later eg

Sub InsertCrossReference()
Dim iFld As Integer
Dim oRange As Range
Dim oColor_Old As WdColor

Set oRange = Selection.Range
'Save current font color
oColor_Old = oRange.Characters(1).Font.Color
'Display cross-reference dialog box
With Dialogs(wdDialogInsertCrossReference)
.InsertAsHyperLink = True
.Show
End With
'Include the inserted cross-reference in oRange
oRange.End = Selection.End
'Apply blue color to oRange
oRange.Font.Color = wdColorBlue
'Reset color after cross-reference
Selection.Font.Color = oColor_Old
'add charformat switch
For iFld = oRange.Fields.Count To 1 Step -1
With oRange.Fields(iFld)
.Code.Text = .Code.Text & " \* CHARFORMAT "
.Update
End With
Next iFld
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
Set oRange = Nothing
End Sub


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Dave wrote:
Hello All,

I have a very long document with a lot of cross references. I am
using the following macro to change the colour of my cross
references to Blue.
Sub InsertCrossReference()

Dim oRange As Range
Dim oColor_Old As WdColor

Set oRange = Selection.Range
'Save current font color
oColor_Old = oRange.Characters(1).Font.Color
'Diaplay cross-reference dialog box
With Dialogs(wdDialogInsertCrossReference)
.InsertAsHyperLink = True
.Show
End With
'Include the inserted cross-reference in oRange
oRange.End = Selection.End
'Apply blue color to oRange
oRange.Font.Color = wdColorBlue
'Reset color after cross-reference
Selection.Font.Color = oColor_Old

Set oRange = Nothing

End Sub

I got it from one of the other newsgroups,it works fine as long
as I don't update my fields. The moment I update the filed the
formatting reverts back to the normal para formatting. So how do
I maintain the formatting even after I update the field.

Thanks in advance
Dave