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!

Pagination and Page Counts in MS Word 1

Status
Not open for further replies.

Scott1116

Programmer
Jan 29, 2010
9
US
My code goes through a folder of documents and deletes a section from each. Sometimes, particularly when Track Changes are on, an unwanted byproduct is a blank page. Accept the changes, and the blank page goes away. I want to keep track of the documents where this happens through these steps:

1. Save the document
2. Get a page count
3. Accept all changes
4. Get a second page count
5. Close without saving
6. Compare the two page counts

Problem: The first page count is often short, I think because the document is still repaginating when I get the count. Here's my latest version of my code, where the idea was to delay further processing until the repagination command completes with an accurate page count (it didn't work):

Code:
ActiveDocument.SaveAs FileName:=rplc_dir & "\" & file_name

ActiveDocument.Repaginate

pgs_chgs_trckd = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

WordBasic.AcceptAllChangesInDoc

ActiveDocument.Repaginate
           
pgs_chgs_acptd = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
           
Debug.Print file_name & " (" & "tracked: " & pgs_chgs_trckd & ", accepted: " & pgs_chgs_acptd & ")"

If pgs_chgs_trckd <> pgs_chgs_acptd Then
...

Any ideas?
 
Instead of
ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

use
ActiveDocument.ComputeStatistics(wdStatisticPages)

:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I just gave that a try -- with and without the first repagination command-- and it's giving me the same numbers as before.

Before my initial post, I also tried ActiveDocument.BuiltInDocumentProperties("Number of Pages") and doing a selection.text from the "Page # of ##" in the footer. I hadn't tried the ComputeStatistics, though, so I'm happy to know about it even if it didn't work here.
 
My problem is solved.

The root cause was I hadn't considered: a combination of hidden text and tracked changes was doing odd things to the page counts. After saving the document and before doing the first page count, I selected all the document text and set font.hidden to false. It yielded perfect results.
 

Scott1116,

Thanks for posting a resolution to your thread.

Don't forget to...
[blue]
Thank MakeItSo
for this valuable post!
[/blue]
The [purple]LITTLE PURPLE STARS[/purple] not only act as a "THANK YOU" to the poster, but also serve to notify other members, browsing the forum, of valuable posts in threads.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ah yes!
Glad you got it sorted.
[thumbsup]

Also don't forget to...
Code:
ActiveDocument.TrackRevisions=False
...turn off revision tracking before accepting the changes.
;-)

Cheers,
MakeItSo

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top