Class Indexes (Word VBA)

A collection of Index objects that represents all the indexes in the specified document.

To use a Indexes class variable it first needs to be instantiated, for example

Dim idxs as Indexes
Set idxs = ActiveDocument.Indexes

Indexes class variables can be set using the Document.Indexes procedure.

For Each

Here is an example of processing the Indexes items in a collection.

Dim idx As Index
For Each idx In ActiveDocument.Indexes
	
Next idx

Add

Returns an Index object that represents a new index added to a document.

An index is built from Index Entry (XE) fields in a document. Use the MarkEntry method to mark index entries to be included in an index.

Add (Range, HeadingSeparator, RightAlignPageNumbers, Type, NumberOfColumns, AccentedLetters, SortBy, IndexLanguage)

ActiveDocument.Indexes.MarkEntry _ 
 Range:=Selection.Range, Entry:="My Entry" 
Set MyRange = ActiveDocument.Content 
MyRange.Collapse Direction:=wdCollapseEnd 
ActiveDocument.Indexes.Add Range:=MyRange, Type:=wdIndexRunin

Arguments

The following argument is required

Range (Range) - The range where you want the index to appear. The index replaces the range, if the range is not collapsed.

Optional arguments

The following arguments are optional

HeadingSeparator (String) - The text between alphabetical groups (entries that start with the same letter) in the index. Can be one of the WdHeadingSeparator constants.

RightAlignPageNumbers (Boolean) - True to align page numbers with the right margin.

Type (WdIndexType) - Specifies whether subentries are on the same line (run-in) as the main entry or on a separate line (indented) from the main entry. Can be either of the following WdIndexType constants: wdIndexIndent or wdIndexRunin.

Possible return values are wdIndexIndent - An indented index, wdIndexRunin - A run-in index.

NumberOfColumns (Long) - The number of columns for each page of the index. Specifying 0 (zero) sets the number of columns in the index to the same number as in the document.

AccentedLetters (Boolean) - True to include separate headings for accented letters in the index (for example, words that begin with "?" and words that begin with "A" are listed under separate headings).

SortBy (WdIndexSortBy) - The sorting criteria to be used for the specified index. Can be either of the following WdIndexSortBy constants: wdIndexSortByStroke or wdIndexSortBySyllable.

Possible return values are wdIndexSortByStroke - Sort by the number of strokes in a character, wdIndexSortBySyllable - Sort phonetically.

IndexLanguage (WdLanguageID) - The sorting language to be used for the specified index. Can be any of the WdLanguageID constants. For the list of valid WdLanguageID constants, see the Object Browser in the Visual Basic Editor.


Here you can find possible values for

WdLanguageID

AutoMarkEntries

Automatically adds XE (Index Entry) fields to the specified document, using the entries from a concordance file.

A concordance file is a Word document that contains a two-column table, with terms to index in the first column and index entries in the second column.

AutoMarkEntries (ConcordanceFileName)

ConcordanceFileName: The concordance file name that includes a list of items to be indexed.

Documents("Thesis.doc").Indexes.AutoMarkEntries _ 
 ConcordanceFileName:="C:\Documents\List.doc"

Count

Returns a Long that represents the number of indexes in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Indexes.Count

Format

Returns or sets a WdIndexFormat that represents the formatting for the indexes in the specified document. Possible return values are wdIndexBulleted - Bulleted, wdIndexClassic - Classic, wdIndexFancy - Fancy, wdIndexFormal - Formal, wdIndexModern - Modern, wdIndexSimple - Simple, wdIndexTemplate - From template.

ActiveDocument.Indexes.Format = wdIndexBulleted

Item

Returns an individual Index object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position of the individual object.

Dim idx As Index
Set idx = ActiveDocument.Indexes(Index:=1)

MarkAllEntries

Inserts an XE (Index Entry) field after all instances of the text in Range.

MarkAllEntries (Range, Entry, EntryAutoText, CrossReference, CrossReferenceAutoText, BookmarkName, Bold, Italic)

If Selection.Type = wdSelectionNormal Then 
 ActiveDocument.Indexes.MarkAllEntries _ 
 Range:=Selection.Range, _ 
 Entry:=Selection.Range.Text, Italic:=True 
 ActiveDocument.Indexes(1).Update 
End If

Arguments

The following argument is required

Range (Range) - The range whose text is marked with an XE field throughout the document.

Optional arguments

The following arguments are optional

Entry (Index) - The text you want to appear in the index, in the form MainEntry[:Subentry].

EntryAutoText (String) - The AutoText entry that contains the text you want to appear in the index (if this argument is specified, Entry is ignored).

CrossReference (Index) - A cross-reference that will appear in the index.

CrossReferenceAutoText (String) - The name of the AutoText entry that contains the text for a cross-reference (if this argument is specified, CrossReference is ignored).

BookmarkName (String) - The bookmark name that marks the range of pages you want to appear in the index. If this argument is omitted, the number of the page that contains the XE field appears in the index.

Bold (Boolean) - True to add bold formatting to page numbers for index entries.

Italic (Boolean) - True to add italic formatting to page numbers for index entries.

MarkEntry

Inserts an XE (Index Entry) field after the specified range. The method returns a Field object representing the XE field.

MarkEntry (Range, Entry, EntryAutoText, CrossReference, CrossReferenceAutoText, BookmarkName, Bold, Italic, Reading)

If Selection.Type = wdSelectionNormal Then 
 ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, _ 
 Entry:="Introduction:" & Selection.Range.Text, Italic:=True 
End If

Arguments

The following argument is required

Range (Range) - The location of the entry. The XE field is inserted after Range.

Optional arguments

The following arguments are optional

Entry (String) - The text that appears in the index. To indicate a subentry, include the main entry text and the subentry text, separated by a colon (:) (for example, "Introduction:The Product").

EntryAutoText (String) - The AutoText entry name that includes text for the index, table of figures, or table of contents (Entry is ignored).

CrossReference (String) - A cross-reference that will appear in the index (for example, "See Apples").

CrossReferenceAutoText (String) - The AutoText entry name that contains the text for a cross-reference (CrossReference is ignored).

BookmarkName (String) - The name of the bookmark that marks the range of pages you want to appear in the index. If this argument is omitted, the number of the page containing the XE field appears in the index.

Bold (Boolean) - True to add bold formatting to the entry page numbers in the index.

Italic (Boolean) - True to add italic formatting to the entry page numbers in the index.

Reading (Boolean) - True shows an index entry in the right location when indexes are sorted phonetically (East Asian languages only).