View Single Post
  #2   Report Post  
Cindy Meister
 
Posts: n/a
Default

Are you familiar with Word's built-in indexing tool: Concordance? You set up
a table with all the terms you want to have indexed, with the index text you
want to use for the term in a second column. Then you call
Insert/References/Index and Tables, and on the "Index" tab click "AutoMark".

-- Cindy

"zalek" wrote:

I have a .txt file - it is a book.
I have another file - it is a list of keywords I want to index in the
book. The keyword can have a few words separated by space. All keywords
are sorted in descending order - there are no duplicates.
Here is my problem:

If a keyword is "book" and another is keyword "book about VBA" -
because the keywords are sorted by descending order, first in the file
will be "book about VBA" and will be indexed. Then "book" comes and
indexes "book about VBA".
How to tell VBA not to index words that are already indexed, that means
do not index the word "book" in "book about VBA".

Thanks,

Zalek

Here is my code:
Sub CreateIndex()

Dim quote As String
Dim Keyword As String
Dim i As Integer
Dim j As Integer
quote = """"
Dim found_key As Boolean
Dim startSearch As Long
Dim endSearch As Long

Close #1
Open "C:\boss_info_index.txt" For Input As #1

i = 0
j = 0
Do While Not EOF(1) ' Loop until end of file.
Set myRange = ActiveDocument.Content
endSearch = myRange.End

Input #1, Keyword

j = 0
i = i + 1

' this is for debugging purpose
If i 500 Then
myRange.Italic = True
Exit Do
End If

While myRange.Find.Execute(FindText:=Keyword, Forward:=True)

myRange.Collapse wdCollapseEnd
Set myIndexEntry = myRange.Fields.Add(myRange,
Type:=wdFieldIndexEntry, _
Text:=quote & Keyword & quote)

startSearch = myRange.End
startSearch = startSearch + 32
myRange.Start = startSearch
myRange.End = endSearch
' this is for debugging purpose
j = j + 1
If j 300 Then
myRange.Bold = True
Exit Sub
End If
Wend


Loop

Close #1 ' Close file.

End Sub