Word VBA - Index headings

M

mrcburns

I support a vb6 application that uses VBA to create a word document on the
fly, it also creates an index. Is there a way to automatically create an
alphabetical character heading at the top of each alphabetical grouping. For
example, the letter 'A' at the top of all the index entries that start with
'a', then the letter 'B' at the top of all the index entries that start with
'b', etc.
 
J

Jay Freedman

That's the purpose of the \h switch that you include in the field code of the
INDEX field. To get a single letter before each group, the field code should
be {INDEX \h "A"} (plus other switches as desired). The formatting of the
letter is determined by the definition of the Index Heading style.
 
M

mrcburns

this is my code:
With wordDoc1
.Indexes.Add Range:=wordApp.Selection.Range, HeadingSeparator:= _
wdHeadingSeparatorNone, Type:=wdIndexIndent,
RightAlignPageNumbers:= _
True, NumberOfColumns:=3, IndexLanguage:=wdEnglishUS
.Indexes(1).TabLeader = wdTabLeaderDots
.Indexes(1).Range.Font.Size = 12
End With

how would I incorporate the field code {INDEX \h "A"} into this?
thanks
 
J

Jean-Guy Marcil

mrcburns was telling us:
mrcburns nous racontait que :
this is my code:
With wordDoc1
.Indexes.Add Range:=wordApp.Selection.Range,
HeadingSeparator:= _ wdHeadingSeparatorNone,
Type:=wdIndexIndent,
RightAlignPageNumbers:= _
True, NumberOfColumns:=3, IndexLanguage:=wdEnglishUS
.Indexes(1).TabLeader = wdTabLeaderDots
.Indexes(1).Range.Font.Size = 12
End With

how would I incorporate the field code {INDEX \h "A"} into this?
thanks

Replace
wdHeadingSeparatorNone
by:
wdHeadingSeparatorLetter

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top