Sign in to follow this  
Followers 0
realshyfox

Word Page Counter

9 posts in this topic

Hy, I´m new here. I´ve been looking but so far I didn´t find a way to find the page count of a word document. I need to know if there is a function that I can call to find how many pages has a word document.

Thank you very much.


Learn, learn and ... learn

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can open the doc, count the words, then close the doc using these functions:

_WordDocOpen()

_WordDocPropertyGet()

_WordDocClose()

Help file tells you how to use them, post code if you still have trouble. I'm not sure how to do this using any other method...but someone else might!

Edited by MrMitchell

Share this post


Link to post
Share on other sites

I´ve been looking and I found this macro that I would like to pass to AutoIt with your help.

Thank you.

Sub GetNumberOfPages()

Activedocument.Repaginate

MsgBox Activedocument.BuiltInDocumentProperties(wdPropertyPages)

End Sub


Learn, learn and ... learn

Share this post


Link to post
Share on other sites

Macro only works with the Doc open, which is what _WordDocOpen() takes care of.

Then _WordDocPropertyGet() does pretty much what the macro you just provided does.

Then _WordDocClose() will close it so you can move on to the next doc.

Share this post


Link to post
Share on other sites

Thank you very much. Your help is very apreciated. If you could help me a litle more ...

How can I a page break after the page x

The macro I use so far:

Sub InsertPageBreak()

Selection.InsertBreak Type:=wdPageBreak

End Sub

Thank you.


Learn, learn and ... learn

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$oWordApp is a Word Application Object, NOT a Word DOC Object

$oWordApp.Selection.GoTo($wdGotoPage, $wdGotoNext, 4) ;Goto page 4

$oWordApp.Selection.InsertBreak($wdPageBreak) ;Insert Page Break

You know, this most likely won't work if you just copy and paste, unless you understand what you're doing and what exactly you're working with here...

Add: And regarding "repaginate", when I tested reading the number of pages of a document, I was getting inaccurate results so I had to add "$oWordDoc.Repaginate" before using _WordDocPropertyGet() to get an accurate page number count.

Edited by MrMitchell

Share this post


Link to post
Share on other sites

$oWordApp is a Word Application Object, NOT a Word DOC Object

$oWordApp.Selection.GoTo($wdGotoPage, $wdGotoNext, 4) ;Goto page 4

$oWordApp.Selection.InsertBreak($wdPageBreak) ;Insert Page Break

You know, this most likely won't work if you just copy and paste, unless you understand what you're doing and what exactly you're working with here...

Add: And regarding "repaginate", when I tested reading the number of pages of a document, I was getting inaccurate results so I had to add "$oWordDoc.Repaginate" before using _WordDocPropertyGet() to get an accurate page number count.

I am a programmer but my language is Visual FoxPro so I have litle knowledge of Visual Basic. But I am working hard on learning this language too. Thank you for pointing me out the way to achieve my goal and I promise that I shall enter more deeply in this.

Thank you again for your help. ;)


Learn, learn and ... learn

Share this post


Link to post
Share on other sites

Cool. Question...i created working code that would loop through a list of Word docs and insert page break on any page, but from where do you get the list of docs and how do you know where to insert the page break on each?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         realshyfox

 Script Function:
    Add MSWord Document PageBreak.

#ce ----------------------------------------------------------------------------

#include<Word.au3>

; WdBreakType 
Const $wdPageBreak = 7 

; wdGoToDirection 
Const $wdGoToNext = 2 


; wdGoToItem 
Const $wdGoToPage = 1 




$oWord    = _WordCreate(@ScriptDir &"\EvacuationGuide.doc", 0, 1)
$oDoc     = _WordDocGetCollection($oWord, 0)
$oDoc.Repaginate
$NumPages = _WordDocPropertyGet($oDoc, "pages")
$i=$NumPages



Do
    $i = $i - 1
    $oWord.Selection.GoTo($wdGotoPage, $wdGotoNext, 1)
    $oWord.Selection.InsertBreak($wdPageBreak)

Until $i = 1
This is my project file. I am sorry that I do not had time to revive this topic. This is what I needed.

Edited by realshyfox

Learn, learn and ... learn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0