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
Greg Maxey - 17 Jan 2005 13:20 GMT
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

Signature
Greg Maxey/Word MVP
A Peer in Peer to Peer Support
> Hi,
> I've made a songbook in MS Word consisting of the lyrics of several
[quoted text clipped - 9 lines]
> Thanks in advance,
> Volker
Volker Schubert - 18 Jan 2005 12:40 GMT
Hi Greg,
this works great!
Thanks a lot! I would have wasted hours by doing that manually.
Volker