Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

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

12 weergaven
Naar het eerste ongelezen bericht

Just_me

ongelezen,
12 mrt 2002, 19:06:1812-03-2002
aan
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

ongelezen,
16 mrt 2002, 20:26:5816-03-2002
aan
> 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 nieuwe berichten