Page number totals... 
Author Message
 Page number totals...

Enclosed is a portion of code taken from a sub that builds
fields dynamically. My main issue is with the page total
and getting it to work properly.

I am adding to the page total a passed parameter
(DataTrans.RepTotalPages) from a VB application, if it
exists. However, wdPropertyPages only accounts for the
total pages when the document is initially opened, if the
user advances a page wdPropertyPages remains unchanged.

I did find that wdFieldNumPages (the three lines of code
that have been commented out) works correctly, but I have
not found a way to add DataTrans.RepTotalPages to it.

Any suggestions or solutions?

'***portion of code:
dim TotalPages     as integer

If txtValue = "PageNumber" Then
     If DataTrans.RepTotalPages <= 0 Then
          TotalPages = _
ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
     Else
          TotalPages = DataTrans.RepTotalPages + _
ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
     End If
     Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldPage
'     Selection.TypeText (" of ")
'     Selection.Fields.Add Range:=Selection.Range, _      
'     Type:=wdFieldNumPages
      Selection.TypeText (" of " & TotalPages)
Else
     Selection.TypeText Text:=txtValue
End If
Selection.ShapeRange.Select

Thank you,
Tony



Tue, 02 Nov 2004 02:16:51 GMT  
 Page number totals...
Hi Tony,

Quote:
> I am adding to the page total a passed parameter
> (DataTrans.RepTotalPages) from a VB application, if it
> exists. However, wdPropertyPages only accounts for the
> total pages when the document is initially opened, if the
> user advances a page wdPropertyPages remains unchanged.

Does
ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
return the correct information, when you require it?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)



Tue, 02 Nov 2004 19:14:57 GMT  
 Page number totals...
Hi Cindy,
ActiveDocument.Range.Information _
(wdNumberOfPagesInDocument),
ActiveDocument.Range.Information _
(wdActiveEndAdjustedPageNumber), and
ActiveDocument.Range.Information(wdActiveEndPageNumber)
in place of ActiveDocument.BuiltInDocumentProperties _
(wdPropertyPages) return the same results. The first
header shows page 1 of 1, but when I advance to the second
page the second header displays page 2 of 1.

Also, yesterday, I tried a way around this by using
wdFieldNumPages, taking the Y value of Page X of Y, adding
the VB app variable, deleting the field, and displaying
the new values.
The result was that all headers displayed the same data
(Page 1 of 1).

'***code sample =
Dim intNumPages     As Integer
Dim strPage         As String

Selection.Fields.Add Range:=Selection.Range, _  
Type:=wdFieldPage
Selection.TypeText (" of ")
Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldNumPages
'grab page field
Selection.SetRange 5, Selection.End
'get page total only
intNumPages = Mid(Selection.Range, InStrRev _
(Selection.Range, " ") + 1)
'add to page total, set TotalPages
TotalPages = intNumPages + DataTrans.RepTotalPages
'get current page and display new page total
strPage = Mid(Selection.Range, 1, InStrRev _
(Selection.Range, " "))
Selection.Delete
Selection.TypeText (strPage & TotalPages)
'*********************************************************'

Quote:
>-----Original Message-----
>Hi Tony,

>> I am adding to the page total a passed parameter
>> (DataTrans.RepTotalPages) from a VB application, if it
>> exists. However, wdPropertyPages only accounts for the
>> total pages when the document is initially opened, if
the
>> user advances a page wdPropertyPages remains unchanged.

>Does
>ActiveDocument.Range.Information

(wdNumberOfPagesInDocument)
Quote:
>return the correct information, when you require it?

>Cindy Meister
>INTER-Solutions, Switzerland
>http://homepage.swissonline.ch/cindymeister
>http://www.mvps.org/word
>http://go.compuserve.com/MSOfficeForum

>This reply is posted in the Newsgroup; please post any
>follow question or reply in the newsgroup and not by e-
mail
>:-)

>.



Wed, 03 Nov 2004 00:16:44 GMT  
 Page number totals...
Hi Tony,

Quote:
> The first
> header shows page 1 of 1, but when I advance to the second
> page the second header displays page 2 of 1.

Well, this is a different problem: what you see in the
header/footer. This is a bug in Word 97 and 2000 that has to
do with printer drivers. Search the Knowledge Base on the MS
website, and you'll come up with at least 4 hits on:
 Wd2000 & NumPages

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)



Wed, 03 Nov 2004 15:46:01 GMT  
 Page number totals...
Thank you, I will check out the info...

Quote:
>-----Original Message-----
>Hi Tony,

>> The first
>> header shows page 1 of 1, but when I advance to the
second
>> page the second header displays page 2 of 1.

>Well, this is a different problem: what you see in the
>header/footer. This is a bug in Word 97 and 2000 that has
to
>do with printer drivers. Search the Knowledge Base on the
MS
>website, and you'll come up with at least 4 hits on:
> Wd2000 & NumPages

>Cindy Meister
>INTER-Solutions, Switzerland
>http://homepage.swissonline.ch/cindymeister
>http://www.mvps.org/word
>http://go.compuserve.com/MSOfficeForum

>This reply is posted in the Newsgroup; please post any
follow
>question or reply in the newsgroup and not by e-mail :-)

>.



Fri, 05 Nov 2004 23:22:59 GMT  
 Page number totals...

Quote:
> Hi Tony,

> > I am adding to the page total a passed parameter
> > (DataTrans.RepTotalPages) from a VB application, if it
> > exists. However, wdPropertyPages only accounts for the
> > total pages when the document is initially opened, if the
> > user advances a page wdPropertyPages remains unchanged.

> Does
> ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
> return the correct information, when you require it?

Well, if

    PageNo = sect.Range.Information(wdActiveEndPageNumber)

doesn't work reliably, then why would your suggestion work either? I
ran a macro with this line over a large document and it screwed up.
But if I let the document sort itself out "in the background", then
ran the macro once Word had finished whatever it was up to, that
worked fine.

If your command is returning inaccurate results, try putting

    ActiveDocument.Repaginate

before you start messing around with page numbers. Fixed things
perfectly for me - it seems if your macro overtakes Word's
repagination before Word has managed to complete its "repaginate on
load", then all the page numbers returned to your macro get screwed.
By forcing the repaginate first, you guarantee that Word has the
correct numbers to hand.

Cheers,
Wol



Sun, 07 Nov 2004 00:17:41 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Adding Total Number of slides to the page number field in the footer

2. Word not printing total number of pages in page footer correctly

3. total number of pages in VBA word

4. total number of pages in all open docs

5. running total page numbers

6. Total Number Pages in Report?

7. total number of pages

8. Total Number of Pages from Formula

9. Crystal - Displaying Total Number of Pages to be Printed

10. Total number of pages in a report?

11. How To Detect Total Page Number ?

12. Total page number

 

 
Powered by phpBB® Forum Software