Jump to content

Word Page Counter


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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

Link to comment
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.

Edited by MrMitchell
Link to comment
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

Link to comment
Share on other sites

  • 7 months later...

#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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...