I need help in creating a macro, that will run on large documents, that will create a index of all the words in the document with their page numbers, in alphabetical order. I have a start of one, but it takes a long time to run and in fact seems to crash word. I would also like the ability to notify the user that it is running so they don't panic and think that it has stopped or crash. Here is what I have so far:
Dim colWords as New Collection
'add words you don't want to index
colWords.Add "and"
colWords.Add "you"
Dim wrd As Range
For Each wrd In ActiveDocument.Words
'only if we have 3 chars we index
If Len(Trim(wrd.Text))
> 2 Then
' prevent the field from being Indexed as well...
Dim infield As
Boolean
infield = False
Dim fld As Field
For Each fld
In ActiveDocument.Fields
If (wrd.Start
>= fld.Code.Start
And wrd.End
<= fld.Code.End)
Then
infield =
True
Exit
For 'break out
End If
Next
If (Not infield)
Then
' check if we already indexed?
Dim findWord
as String
findWord = LCASE(wrd.Text)
For Each cached
in colWords
if cached
= findWord Then
infield
= True
Exit For 'break out
end
If
Next
If
(Not infield) Then
ActiveDocument.Indexes.MarkAllEntries Range:=wrd, Entry:=wrd.Text,
_
EntryAutoText:=wrd.Text, CrossReference:="",
CrossReferenceAutoText:="", _
BookmarkName:="", Bold:=False, Italic:=False
colWords.Add findWord
End
If
End If
End If
Next