Group: microsoft.public.word.vba.general
From: =?Utf-8?B?TmFubmll?=
Date: Sunday, January 27, 2008 12:45 PM
Subject: RE: Dictionary Style headers in an index

Lene,
I installed your macro and, unfortunately, it did not solve the problem. It
changed all of the index text to HeaderCharStyle. I still get too much
information in the header (as before) and lose the formatting of level 2
indices (indentation) and two column formatting.
I DO appreciate your help, though!
--
Nannie


"Lene Fredborg" wrote:

> 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
>
>
> "Nannie" wrote:
>
> > I tried assigning a character style to just the surname but as soon as the
> > index is re-generated, those assigned character styles are lost. But thanks
> > for replying!!
> > --
> > Nannie
> >
> >
> > "Lene Fredborg" wrote:
> >
> > > See the following article for tips on how you can accomplish what you want by
> > > using a character style:
> > > http://sbarnhill.mvps.org/WordFAQs/StyleRef.htm
> > >
> > > --
> > > Regards
> > > Lene Fredborg
> > > DocTools - Denmark
> > > www.thedoctools.com
> > > Document automation - add-ins, macros and templates for Microsoft Word
> > >
> > >
> > > "Nannie" wrote:
> > >
> > > > I have a generated index and used StyleRef to build running headers
> > > > successfully using Index1. However, the header includes too much information.
> > > > For example: Adams, George F of Company C 14, 25, 99. I'd like to truncate
> > > > it to whatever comes before the comma. How can I do this?
> > > > --
> > > > Nannie