Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word count for each page .... can it be put in a footer ? 1

Status
Not open for further replies.

FoxEgg

Programmer
Mar 24, 2002
749
AU
The professor wants EACH PAGE in an Essay (done in Word) to have a word count ... (as well as a total document word count on the title page)

Is there a way that this can be done other that selecting text then using word count, getting the Word Count and then manually copying the word count ????

Help....

Thanks

(PS We have Word 2000)

FoxEgg
jfox2@bigpond.net.au
 
Sounds like coursework to me. I don't like to answer, but will definitely try to help. Have you checked the fields available? Anne Troy
Dreamboat@TheWordExpert.com
Anne@MrExcel.com
 
Sounds like coursework to me ???

Yes, it is... my wife is doing law (Sydney) and they seem to be pedants on word count...

... Have you checked the fields available?

Do you mean automation ??? I (sort of) program VFP but am just a garden variety "user" when it comes to Word Processing... and I can't do it by travelling around the popups (except by highlighting and Word Counting; and even then then there is no cut and paste option... I did a Web search with no luck also.. Hence Tek-Tips and the call for help

Thanks for replying, if you could give me some direction I'd (we'd) be grateful.


John Fox
 
Not mine, so can't take credit for it

Sub CountWordsOnPage()
Dim oRg As Range
Dim numwords As Long, numpages As Long, pg As Long

For pg = 1 To ActiveDocument.Range.Information(wdActiveEndPageNumber)
Selection.GoTo what:=wdGoToPage, which:=wdGoToAbsolute, Count:=pg
Set oRg = ActiveDocument.Bookmarks("\page").Range
numwords = oRg.Words.Count
MsgBox "page " & pg & vbTab & numwords & " words"
Next pg
End Sub
 
Does that work, John? Anne Troy
Dreamboat@TheWordExpert.com
Anne@MrExcel.com
 
Genuine thanks Onedtent and Dreamboat (great names for Techs and Instructors respectively) both for your suggestions and encouragement....

Now I gotta work out where to stick that dang code...

I have never programmed Word before ... can you give some tips as to where I should look or how I should do it ?

In the meantime I will experiment....

Thx


John Fox
 
Having never done this before in my life--- >
I ran
Tools>Macro>ScriptEditor pasted code (and I dont know if I saved it or not)

Loaded a document and Hey Presto... a little window appears on the screen....

Absolutely MAGIC !

Now can I get that Word Count to write into a Footer which says:

Word Count this page is XXXX words

Thanks again... great suggestion

John
 
Whoops sorry that should be MACROS- VisualBASIC EDITOR (not script editor)
 
Reading his code, but not being a coder myself, it looks like you need to insert a bookmark called "\page" into the footer. But don't include the quotes. I didn't test it. Anne Troy
Dreamboat@TheWordExpert.com
Anne@MrExcel.com
 
& perhaps appropriate (re: your comment)

This macro gives u the word count per page in a message box. I may be mistaken but, to be able to actually insert this number in a footer would require code to add a continuous section break after each page - remove "Same as previous" attribute of the footer and then insert the word count. I am pretty good at simple coding but that's where it ends.
 
Thanks team...(particularly the Philly cheer leader)

I tried saving the screen to a .bmp then cutting and pasting. Clumsy but it works.

At the risk of insulting your great work ... Should I repost the request to see if a coding doyen can get the Number into a footer >>>??

I have ABSOLUTELY NO IDEA HOW TO PROGRAM WORD...

Thankyou

 
hi John

stroke of lightening (however, not there yet)

Instead of trying to put the word count in a footer, the better idea would be to put it in a text box without borders where footer would normally be. I have got the code working somewhat, this is 'cause I am not a "doyen".(I had to go consult Merriam for that). It does put a text box with a word count at the end of the document. Perhaps some higher intelligence can help you put it on every page.

Sub txtbox()

Dim oRg As Range
Dim numwords As Long, NumPages As Long, pg As Long

For pg = 1 To ActiveDocument.Range.Information(wdActiveEndPageNumber)
Selection.GoTo what:=wdGoToPage, which:=wdGoToAbsolute, Count:=pg
Set oRg = ActiveDocument.Bookmarks("\page").Range
numwords = oRg.Words.Count

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 90#, _
308#, 72#, 72#).Select

Selection.ShapeRange.Select
Selection.TypeText Text:=numwords
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Line.Visible = msoFalse
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Height = 72#
Selection.ShapeRange.Width = 72#
Selection.ShapeRange.Left = InchesToPoints(-0.63)
Selection.ShapeRange.Top = InchesToPoints(7.63)
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.ScaleHeight 0.5, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.IncrementLeft 9#
Selection.ShapeRange.IncrementTop 36#


Next pg

End Sub
 
Thanks Onedtent..

I am not getting e-mail notifications from Tek-Tips; sorry I didn't reply earlier.. so I havent treid this YET buit I will this weekend.

John
jfox@orthopaedicassociates.com.au
 
John!

Finally got it working. here it is

Sub txtbox()

Dim oRg As Range
Dim numwords As Long, NumPages As Long, pg As Long

For pg = 1 To ActiveDocument.Range.Information(wdActiveEndPageNumber)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=pg
Set oRg = ActiveDocument.Bookmarks("\page").Range
numwords = oRg.Words.Count

Set myTbox = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 80#, _
720#, 120#, 24#)

myTbox.TextFrame.TextRange = "Word Count = " & numwords
myTbox.Select
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Line.Visible = msoFalse
Selection.ShapeRange.LockAspectRatio = msoFalse


Next pg

End Sub


what you need to do to make it work:

open ur word file. got to tools, macro, visual basic editor
go to insert, module
and paste the code in the window that pops up
u can minimize or close the VB window
save ur file with a different name (this is for Justin Kayce)

go to tools, macro, macros and run the txtbox macro

la fin

 
That works like a bloody charm !!!!!

Oded you are a God! (or G_d if is more appropriate)

A MEGA STAR POSTED

Another quick question.... in your line...

myTbox.TextFrame.TextRange = "Word Count = " & numwords

is it possible to put the page number eg

myTbox.TextFrame.TextRange = "Page Number" _here goes the real page number__ " Word Count = " & numwords


A thousand thankyous from me and my wife... PS we named the macro Oded

John Fox
Oz
 
Try this

myTbox.TextFrame.TextRange = "Page Number" & pg & ":- Word Count = " & numwords

 
slight correction to Sangeeth's

myTbox.TextFrame.TextRange = "Page Number " & pg & " Word Count = " & numwords

that takes care of the spaces. There is a however in there somewhere. You will probably will have to play with the following statement and change the 120# to something higher. Try something around 200 - 250.

Set myTbox = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 80#, _
720#, 120#, 24#)

You may want to shorten your text box to
myTbox.TextFrame.TextRange = "Page " & pg & " Word Count = " & numwords


If you do go with the shorter version than the 120# might change to 170 - 200

an onedtent
 

Thanks again... all worked superbly.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top