Reply
 
Thread Tools Display Modes
  #1   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

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

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to maintain the formatting of a Cross Reference

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



  #3   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 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



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to maintain the formatting of a Cross Reference

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



  #5   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 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





  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to maintain the formatting of a Cross Reference

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



  #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



  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to maintain the formatting of a Cross Reference

You are welcome

--

Graham Mayor - Word MVP

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



Dave wrote:
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



  #9   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to maintain the formatting of a Cross Reference

On further reflection you might usefully change

If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"\* MERGEFORMAT", "\* CHARFORMAT")
End If
to
If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"MERGEFORMAT", "CHARFORMAT")
End If

--

Graham Mayor - Word MVP

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


Dave wrote:
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



  #10   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 I will try it out and let you know how it goes. Just curious though,
but what is the difference between this marco and the one you gave
previously.

Thanks
Dave

"Graham Mayor" wrote in message
...
On further reflection you might usefully change

If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"\* MERGEFORMAT", "\* CHARFORMAT")
End If
to
If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"MERGEFORMAT", "CHARFORMAT")
End If

--

Graham Mayor - Word MVP

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


Dave wrote:
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





  #11   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How to maintain the formatting of a Cross Reference

The original replaced \*MERGEFORMAT with \*CHARFORMAT but would not account
for
\* MERGEFORMAT ie with a space. The replacement code only changes the
MERGEFORMAT part of the string.

--

Graham Mayor - Word MVP

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


Dave wrote:
Thanks I will try it out and let you know how it goes. Just curious
though, but what is the difference between this marco and the one you
gave previously.

Thanks
Dave

"Graham Mayor" wrote in message
...
On further reflection you might usefully change

If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"\* MERGEFORMAT", "\* CHARFORMAT")
End If
to
If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"MERGEFORMAT", "CHARFORMAT")
End If

--

Graham Mayor - Word MVP

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


Dave wrote:
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



  #12   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

ok. Thanks again for all the help

"Graham Mayor" wrote in message
...
The original replaced \*MERGEFORMAT with \*CHARFORMAT but would not
account for
\* MERGEFORMAT ie with a space. The replacement code only changes the
MERGEFORMAT part of the string.

--

Graham Mayor - Word MVP

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


Dave wrote:
Thanks I will try it out and let you know how it goes. Just curious
though, but what is the difference between this marco and the one you
gave previously.

Thanks
Dave

"Graham Mayor" wrote in message
...
On further reflection you might usefully change

If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"\* MERGEFORMAT", "\* CHARFORMAT")
End If
to
If InStr(1, UCase(.Code), "MERGEFORMAT") 0 Then
.Code.Text = replace(.Code.Text, _
"MERGEFORMAT", "CHARFORMAT")
End If

--

Graham Mayor - Word MVP

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


Dave wrote:
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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross-reference Formatting Jacquiemal Microsoft Word Help 6 November 2nd 07 04:20 PM
Insert reference/cross-reference doesn't display my header text Babs25 Microsoft Word Help 3 October 24th 07 01:49 PM
Cross-reference--Error! Reference source not found. hbear Microsoft Word Help 2 March 2nd 07 05:27 PM
(cross-reference usage)I see "Error! Reference source not found". spiderou Microsoft Word Help 2 July 8th 05 09:34 PM
SEQ Field not in cross-reference reference type pull-down menu The Josh Microsoft Word Help 5 May 25th 05 02:27 PM


All times are GMT +1. The time now is 01:30 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"