Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how? - list all words in a document with their resp. page #s

11 views
Skip to first unread message

Just_me

unread,
Mar 12, 2002, 7:06:18 PM3/12/02
to
How would I accomplish this with VBA. I have never programmed at all with
VBA and am trying to get started, but something that should be so easy to do
seems not so easy.

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

Klaus Linke

unread,
Mar 16, 2002, 8:26:58 PM3/16/02
to
> Anyway I just would like to see some code to list all words in
> a document along with their respective page numbers.


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

0 new messages