Yes, you will need to apply the character style as the last thing after you
have finished the editing and updated the index. If this is not an option,
you could use a macro to update the index and apply the character style. See
below.
Preconditions:
1. You have defined a character style named "HeaderCharStyle" (change the
name in the macro if you want another style name).
2. Your header contains a StyleRef field with the code:
{ StyleRef "HeaderCharStyle" }
The macro below first updates the index (and thereby removes any previously
applied character style). Then the macro iterates through all paragraphs in
the index. If one or more commas are found in the paragraph, the macro will
find the text until the first comma and apply the HeaderCharStyle. If no
commas are found, HeaderCharStyle will be applied to the entire paragraph
(minus the paragraph mark). The StyleRef field in the header should
automatically be updated.
Sub ApplyCharacterStyleToIndex()
Dim oPara As Paragraph
Dim oRange As Range
If ActiveDocument.Indexes.Count >= 1 Then
'Update index
ActiveDocument.Indexes(1).Update
For Each oPara In ActiveDocument.Indexes(1).Range.Paragraphs
'The first item may be a section break that starts the index
'in that case, skip it - Chr(12)
If oPara.Range.Text = Chr(12) Then
GoTo Skip
End If
'Get the text in the paragraph without the paragraph mark
Set oRange = oPara.Range
With oRange
.End = .End - 1
'If comma in text, reduce until no comma
Do Until InStr(1, .Text, ",") = 0
.End = .End - 1
Loop
'Apply character style to text
'Replace "HeaderCharStyle" by the style name you defined
.Style = "HeaderCharStyle"
End With
Skip:
Next oPara
End If
'Clean up
Set oRange = Nothing
End Sub
For help on installing macros, see:
http://www.gmayor.com/installing_macro.htm
--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word