Index from Titles

  • Thread starter Volker Schubert via OfficeKB.com
  • Start date
V

Volker Schubert via OfficeKB.com

Hi,
I've made a songbook in MS Word consisting of the lyrics of several songs. The songs themselves are arranged by genre, e.g. rock songs, folk songs, etc.. The titles of the songs are formatted in a special header style.
What I'd like to do is to automatically generate index entries (i.e. XE fields) for the title headers. I.e., whereever the special header style is found, an index entry with the header text should be generated.

Has anybody some idea how this could be accomplished?

Thanks in advance,
Volker
 
G

Greg Maxey

Volker,

Maybe something like this (change Heading 1 to our title style name):


Sub IndexHeadingSytle()
Dim oFld As Field
Dim oPara As Paragraph
Dim myRange As Range
Dim oDoc As Document

Set oDoc = ActiveDocument
With ActiveWindow.View
.ShowFieldCodes = False
.ShowHiddenText = False
.ShowAll = False
End With
'Prevent double indexing
For Each oFld In oDoc.Fields
If oFld.Type = wdFieldIndexEntry Then oFld.Delete
Next

For Each oPara In oDoc.Paragraphs
Set myRange = oPara.Range
If oPara.Style = "Heading 1" Then
Set myRange = oPara.Range
oDoc.Indexes.MarkEntry Range:=myRange, Entry:=Trim(myRange.Text)
End If
Next oPara

End Sub
 
V

Volker Schubert via OfficeKB.com

Hi Greg,

this works great!

Thanks a lot! I would have wasted hours by doing that manually.

Volker
 

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