word count in word 2007

  • Thread starter Thread starter scott
  • Start date Start date
S

scott

im trying to automatically add a word count to the bottom of each page in a
document created in word 2007 can anyone help me please
 
You can do it using a NumWords field in the footer, but note that it won't
be a word count for the page but for the whole document. You can select text
(the whole page, for example) and get a word count for the selection, but
there's no field for that, nor any switch to tell NumWords to count just a
selection.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
Scott,

No small challenge and you may not be satisfied with the result. Part of
the problem is if the page is already "full" of words then adding more
(i.e., the word count) would push existing words to the next page. That
part can be overcome.

The problem that will likely lead to unsatisfactory results is the type of
things that Word considers a words.

Try running the following macro. This computes the number of words in a
built-in bookmark "\Page" range for each page and displays the results in a
textbox outside the traditional margins.

Sub ComputeWordsPerPage()
Dim oRng As Word.Range
Dim oShape As Shape
Dim oCount As Long
Set oRng = ActiveDocument.Content
oRng.Collapse wdCollapseStart
oRng.Select
Do
Set oRng = Selection.Bookmarks("\Page").Range
oCount = oRng.ComputeStatistics(wdStatisticWords)
oRng.Collapse wdCollapseEnd
oRng.Move wdCharacter, -1
Set oShape =
ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 125,
20)
With oShape
.TextFrame.TextRange.Text = oCount & " words this page."
.Left = InchesToPoints(0)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Top = InchesToPoints(9)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
End With
oRng.Move wdCharacter, 1
oRng.Select
Loop Until oRng.End = ActiveDocument.Range.End - 1
End Sub
 
Scott,

I have added a bit of refinement to the macro so if the word count changes
it is easier to update the displayed count:

Sub ComputeWordsPerPage()
Dim oRng As Word.Range
Dim i As Long
Dim oShape As Shape
Dim oCount As Long
Set oRng = ActiveDocument.Content
oRng.Collapse wdCollapseStart
oRng.Select
i = 1
Do
On Error Resume Next
Set oShape = ActiveDocument.Shapes("Page " & i & " word count")
oShape.Delete
On Error GoTo 0
Set oRng = Selection.Bookmarks("\Page").Range
oCount = oRng.ComputeStatistics(wdStatisticWords)
oRng.Collapse wdCollapseEnd
oRng.Move wdCharacter, -1
Set oShape =
ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 160,
24)
With oShape
.Name = "Page " & i & " word count"
.TextFrame.TextRange.Text = "This page contains " & oCount & " words."
.Fill.ForeColor = wdColorLightYellow
.Left = InchesToPoints(0)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Top = InchesToPoints(9.25)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
End With
oRng.Move wdCharacter, 1
oRng.Select
i = i + 1
Loop Until oRng.End = ActiveDocument.Range.End - 1
End Sub
 
Back
Top