Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

put wordcount for each page on page header automatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FotoArt - 04 Aug 2006 09:35 GMT
hello everyone
I write news scripts in MS Word and I need my wordcount of every page
somewhere, preferrably on teh header.
Is there a way I could achieve this.
If the info could be updated everytime I save would be great.
Hope some one could help.

thanx
ahmed
Jezebel - 04 Aug 2006 11:19 GMT
No, there's no easy way to do this.

Why do you care how many words are on your page?

> hello everyone
> I write news scripts in MS Word and I need my wordcount of every page
[quoted text clipped - 5 lines]
> thanx
> ahmed
FotoArt - 04 Aug 2006 18:33 GMT
Hello Jezebel

Its for my work. my scripts are counted in sec/min. I would convert the
number of words to seconds and display at the top.

You dont have to give me the full code, culd u please tell me the steps at
least how it could be worked out.

I have a code that counts and displays the total length of the document.

> No, there's no easy way to do this.
>
[quoted text clipped - 9 lines]
> > thanx
> > ahmed
Greg Maxey - 04 Aug 2006 19:09 GMT
Jezebel is at lease several orders of magnitude better qualified to
answer but I will give it a stab.

When he says that there is no easy way...I would say if there is a way
it would likely be incredibly complex.

There are several factors.  First what you call a page (on your machine
or as the output of your printer) is likely different if I opened your
document on my machine or printed it with my printer.  A Word document
only becomes organized as pages at the output of the printerdriver
(which also drives the screen display). Different drivers = different
pages.

Secondly, creating different header text based on the content of a page
(whether that be some text or some count) is complex in itself.  See:

http://gregmaxey.mvps.org/Conditional_Headers_Footers.htm for an
example.

So if you abandon the header idea then it is back to somewhere on the
page.  Well that will add complexity as you will then have to figure
out how to exclude the text of the count itself.

There is a relatively simple way but it requires that you divide each
page of your document into a section (i.e., at the end of each page
insert a section break).  Then you could use the following:

Sub ScratchMacro()
Dim oDoc As Document
Dim oSec As Section
Dim oRng As Range
Set oDoc = ActiveDocument
For Each oSec In oDoc.Sections
  With oSec.Headers(wdHeaderFooterPrimary)
    .LinkToPrevious = False
    Set oRng = .Range
    With oRng
      .ParagraphFormat.Alignment = wdAlignParagraphRight
      .Text = oSec.Range.ComputeStatistics(wdStatisticWords)
    End With
 End With
Next
End Sub

> Hello Jezebel
>
[quoted text clipped - 19 lines]
> > > thanx
> > > ahmed
FotoArt - 05 Aug 2006 17:29 GMT
Hey Greg thanx
That was just what I was looking for.
Works fine.
I cant thank you enough. You have saved me a lot of time every work hour.

cheers
ahmed

> Jezebel is at lease several orders of magnitude better qualified to
> answer but I will give it a stab.
[quoted text clipped - 63 lines]
> > > > thanx
> > > > ahmed
FotoArt - 05 Aug 2006 18:11 GMT
Hello Greg
just one more thing if you could help.
Your code works fine.
Is there a way I could add a text, lets say, "words" just before the
wordcount in the header.
And if you could please. How could I add page numbers and an additional text
on the same line in the header.
I have tried somethin like

.Text = (oSec.Range.ComputeStatistics(wdStatisticWords)) , "words"
but didnt work.

Any help would be appreciated.

thanx

ahmed

> Hey Greg thanx
> That was just what I was looking for.
[quoted text clipped - 71 lines]
> > > > > thanx
> > > > > ahmed
Greg Maxey - 05 Aug 2006 18:31 GMT
Try:

Sub ScratchMacro()
Dim oDoc As Document
Dim oSec As Section
Dim oRng As Range
Set oDoc = ActiveDocument
For Each oSec In oDoc.Sections
  With oSec.Headers(wdHeaderFooterPrimary)
    .LinkToPrevious = False
    Set oRng = .Range
    With oRng
      .Text = "Page Number:  "
      .Collapse wdCollapseEnd
      .Fields.Add oRng, wdFieldPage
      .Collapse wdCollapseEnd
      .Move wdCharacter, 1
      .Text = ".  Word Count: " &
oSec.Range.ComputeStatistics(wdStatisticWords)
    End With
 End With
Next
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hello Greg
> just one more thing if you could help.
[quoted text clipped - 92 lines]
>>>>>> thanx
>>>>>> ahmed
FotoArt - 05 Aug 2006 19:01 GMT
Hello Greg
the line below is giving a syntax error
.Text = "  Word Count: " &

thanx
ahmed

> Try:
>
[quoted text clipped - 116 lines]
> >>>>>> thanx
> >>>>>> ahmed
FotoArt - 05 Aug 2006 19:05 GMT
Hey Greg

Its working fine
I deleted the ampersand and its working cool

thanks a lot

ahmed

> Hello Greg
> the line below is giving a syntax error
[quoted text clipped - 123 lines]
> > >>>>>> thanx
> > >>>>>> ahmed
FotoArt - 06 Aug 2006 14:16 GMT
hello greg

i have modified the code as follows

Sub ScratchMacro()
Dim lngWords As Long
Dim pMinutes As Long
Dim oDoc As Document
Dim oSec As Section
Dim oRng As Range
Set oDoc = ActiveDocument

For Each oSec In oDoc.Sections
  With oSec.Headers(wdHeaderFooterPrimary)
    .LinkToPrevious = False
    Set oRng = .Range
    With oRng
      .Text = "Page: "
      .Collapse wdCollapseEnd
      .Fields.Add oRng, wdFieldPage
      .Collapse wdCollapseEnd
      .Move wdCharacter, 1
         lngWords = oSec.Range.ComputeStatistics(wdStatisticWords)
         pMinutes = (lngWords / 3)
      .Text = "     Length: " & Format$(pMinutes / 86400, "hh:mm:ss")
      .Collapse wdCollapseEnd
      .Fields.Add oRng, wdFieldDate, "\@ ddd-d-MMM-yyyy"
      .Text = "     Date: "
     
    End With
 End With

Any idea why the length and date wouldnt show up after page 9 of any
document. However the page number is shown until the end of the documnt.
every new page is a new section.

Any help would be appreciated

thanx
ahmed

> Hey Greg
>
[quoted text clipped - 132 lines]
> > > >>>>>> thanx
> > > >>>>>> ahmed
Greg Maxey - 06 Aug 2006 17:06 GMT
This was a puzzle ;-).  It has to do with the move character statement.
When the number of pages exceeded one digit then it messed up.

Change:
.Move wdCharacter, 1
To:

.Move wdCharacter, 2  'or 3 if you have more than 99 pages.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> hello greg
>
[quoted text clipped - 180 lines]
>>>>>>>>>> thanx
>>>>>>>>>> ahmed
FotoArt - 06 Aug 2006 18:33 GMT
Hello Greg

thanx for the help
Its working fine

Ahmed

> This was a puzzle ;-).  It has to do with the move character statement.
> When the number of pages exceeded one digit then it messed up.
[quoted text clipped - 189 lines]
> >>>>>>>>>> thanx
> >>>>>>>>>> ahmed
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.