Count the number of words in a line?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
Is there a way of counting how many words are in a line. I have seen somewhere (cant remember where), that put the number of words in a line at the end of each line. So for example, if I type "Test to see" at the end of that it puts in 3.
Does anyone know?
Help appreciated.
Thanks in advance
 
This could be done using a macro. However, there's nothing built into Word
that does that automatically.

--
Herb Tyson MS MVP
Please respond in the newsgroups so everyone can follow along.
http://www.herbtyson.com
FED UP!! said:
Hello
Is there a way of counting how many words are in a line. I have seen
somewhere (cant remember where), that put the number of words in a line at
the end of each line. So for example, if I type "Test to see" at the end of
that it puts in 3.
 
Sure. First, with the cursor located anywhere in the line, press Home
key to bring the cursor to the start of the line. Then press Shift+End
which will select up to the end of the line. Then open Tools,
WordCount, which will open the WordCount box which will display the
number of words, characters and so on in the selection.

If you run Tools, Wordcount without a selection, it gives the number of
words, characters etc. in the document.

Larry
 
Thank you Larry. It works!! I knew there was way of doing it - but couldnt figure it out. (Wasnt having a good day yesterday).....!
----- Larry wrote: ----

Sure. First, with the cursor located anywhere in the line, press Hom
key to bring the cursor to the start of the line. Then press Shift+En
which will select up to the end of the line. Then open Tools
WordCount, which will open the WordCount box which will display th
number of words, characters and so on in the selection

If you run Tools, Wordcount without a selection, it gives the number o
words, characters etc. in the document

Larr



FED UP!! wrote
 
Run a macro containing the following code:

MsgBox ActiveDocument.Bookmarks("\line").Range.Words.Count


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
The Words.Count method:

MsgBox ActiveDocument.Bookmarks("\line").Range.Words.Count

counts punctuation and paragraph marks as well as real words. To get
the number of real words, you need to use the ComputerStatistics method
like this:

MsgBox
ActiveDocument.Bookmarks("\line").Range.ComputeStatistics(wdStatisticWor
ds)

If you want a nicer dialog box, you could use this:

MsgBox "Words in current line " & _

Format(ActiveDocument.Bookmarks("\line").Range.ComputeStatistics(wdStati
sticWords), _
"#,##0"), vbOKOnly, "Words in Line"

However, there is a bug in Word 97, so that, while the Computer
Statistics method will work correctly on the whole document, it will not
work consistently on a selection or range. This bug was fixed either in
Word 2000 or Word 2002.

Larry


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL
 
However, even if you do have Word 97, the ComputeStatistics seems to
work ok if the number involved is small, so you could use the macro I
gave you. I've run this several times on a single lines of varying
width in my Word 97 and it hasn't gone wrong yet. It's only when I try
the same thing on a range or selection larger than a line that it goes
wrong.

Larry
 
Back
Top