how to add a running word count

S

Shejju

i want to add a running word count at the end of every page on my essay and
is it able to do it automatically? i am using Microsoft Word 2007
 
D

Doug Robbins - Word MVP

You cannot do it automatically. However, if you run a macro containing the
following code when your document is the active document, it will create a
new document with each page of your document in a separate Section and with
the running word count in the footer of each Section.

Dim Counter As Long, i As Long
Dim Source As Document, Target As Document
Dim rngTarget As Range
Dim strPages As String
Dim arrPagee As Variant
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey Unit:=wdStory
Pages = Source.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
strPages = ""
While Counter < Pages
Counter = Counter + 1
With Source.Bookmarks("\Page").Range
strPages = strPages & "|" & .Words.Count
.Copy
End With
Set rngTarget = Target.Range
rngTarget.Collapse wdCollapseEnd
rngTarget.Paste
Set rngTarget = Target.Range
rngTarget.Collapse wdCollapseEnd
rngTarget.InsertBreak wdSectionBreakNextPage
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1
Wend
arrPages = Split(strPages, "|")
Counter = 0
With Target
For i = 1 To .Sections.Count - 1
With .Sections(i).Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False
Counter = Counter + Val(arrPages(i))
.Range.Text = Counter
End With
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top