Anyway I just would like to see some code to list all words in a document
along with their respective page numbers.
Thank you,
Wayne
Hi Wayne,
As a "feasibility study" see my macro below.
Like most indexes, it lists every word only once for each page.
Since the official limit on the number of fields in a document is
32000, you'll run into trouble with long documents. So you'd better
exclude punctuation and the most common words.
A progress bar or something like that also wouldn't be bad in a macro
that takes so much time...
And perhaps there is a possibility to put in the same Entry for
different word forms ("run", "ran", "Running" ...)?
With most macros, there's always room for improvement.
To get the hang of programming in VBA, have a look at the articles in
the "Macros/VBA" section of the MVP's FAQ page, especially Bill Coan's
http://www.mvps.org/word/FAQs/MacrosVBA/VBABasicsIn15Mins.htm
And turn on everything in the VB editor's "Tools > Options > Editor"
to get all the help you can while writing code.
Good luck,
Klaus
Sub IndexAllWords()
' index all words, and put the index at end of doc
Dim myWord As Range
ActiveWindow.View.ShowFieldCodes = False
ActiveWindow.View.ShowHiddenText = False
ActiveWindow.View.ShowAll = False
For Each myWord In ActiveDocument.Words
ActiveDocument.Indexes.MarkEntry _
Range:=myWord, _
Entry:=Trim(myWord.text)
Next myWord
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
ActiveDocument.Indexes.Add Range:=Selection.Range
End Sub