Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Cross-reference Formatting | Microsoft Word Help | |||
Insert reference/cross-reference doesn't display my header text | Microsoft Word Help | |||
Cross-reference--Error! Reference source not found. | Microsoft Word Help | |||
(cross-reference usage)I see "Error! Reference source not found". | Microsoft Word Help | |||
SEQ Field not in cross-reference reference type pull-down menu | Microsoft Word Help |