realshyfox Posted October 15, 2010 Posted October 15, 2010 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
MrMitchell Posted October 15, 2010 Posted October 15, 2010 (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 October 15, 2010 by MrMitchell
realshyfox Posted October 15, 2010 Author Posted October 15, 2010 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
MrMitchell Posted October 15, 2010 Posted October 15, 2010 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.
realshyfox Posted October 15, 2010 Author Posted October 15, 2010 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
MrMitchell Posted October 15, 2010 Posted October 15, 2010 (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 October 15, 2010 by MrMitchell
realshyfox Posted October 16, 2010 Author Posted October 16, 2010 $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 BreakYou 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
MrMitchell Posted October 16, 2010 Posted October 16, 2010 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?
realshyfox Posted May 25, 2011 Author Posted May 25, 2011 (edited) expandcollapse popup#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 = 1This is my project file. I am sorry that I do not had time to revive this topic. This is what I needed. Edited May 25, 2011 by realshyfox Learn, learn and ... learn
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now