Index

M

Matthias

I want to index a book in word - and there are already hundreds of exisiting
index entries in the text, produced an older programm.

There are two forms (both nomal text in the file):
- <$Imainentry>
- <$mainetry;subentry>.

Can this be achieved in VBA? Replace these existing text fields with word
index fields {XE }?

Thanks for every answer/help!

Matthias
 
D

Doug Robbins - Word MVP

I am not really clear about what is actually in the document -

There are two forms (both nomal text in the file):
- <$Imainentry>
- <$mainetry;subentry>.

Can you paste a chunk of the text that contains such items into a message so
that I, at least, can be sure what you have to start with.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Matthias

Thanks for your answer.
Here is an example, with in total three index entries (two with only main
entry, the third with additional subentry):

The currently relevant results <$Iresults;relevant> from this development
<$Idevelopment> are the following approvals <$Iapprovals>.
 
D

Doug Robbins - Word MVP

The following code should convert entries such as that to XE field codes:

Dim myrange As Range, Code As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="\<$I*\>", Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
myrange.Text = Replace(myrange.Text, ";", ":")
Code = Mid(myrange, 4, Len(myrange) - 4)
myrange.Text = ""
ActiveDocument.Fields.Add myrange, wdFieldEmpty, "XE " &
Code
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Matthias

Dear Doug,

thank you so much for your help, it works! I´ve got only one problem, all
replaced index entries look like following:

{ XE approvals \* MERGEFORMAT }

Can you give me a tip how the string \* MERGEFORMAT can be avoided?

Thanks in advance for your fantastic work!
 
K

Klaus Linke

Hi Matthias,

Replace the line starting with ActiveDocument.Fields.Add:

ActiveDocument.Fields.Add _
Range:=myrange, _
Type:=wdFieldEmpty, _
Text:="XE " & Chr(34) & Code & Chr(34), _
PreserveFormatting:=False
' The last line gets rid of \* MERGEFORMAT

Regards,
Klaus
 

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