Sign in to follow this  
Followers 0
water

[SOLVED] Wrong Pagenumbers when printing with word.au3

2 posts in this topic

#1 ·  Posted (edited)

Hi AutoIt and Word gurus,

I have a strange problem with word and word.au3 and would very much appreciate your help :D

I use the following code to print word documents to a printer driver that generates PDF-files:

Func _Word2PDF($File)
    
    Dim $WordExists = False          ; Words not running yet
    
    If ProcessExists("winword.exe") Then $WordExists = True
    
    ; create MS Word application
    $oWordApp = _WordCreate("")
    If @error then _ShowError("_WordCreate Error")
    
    ; Close empty document
    $oDoc = _WordDocGetCollection ($oWordApp, 0)
    _WordDocClose($oDoc,0)
    
    $oWordApp.Options.WarnBeforeSavingPrintingSendingMarkup = False
    $oWordApp.Options.UpdateLinksAtOpen = False
    
    ; open document
    $oDoc = _WordDocOpen($oWordApp,$file,0,0,1)
    If @error then _ShowError("_WordDocOpen Error")
    
    $oWordApp.Activedocument.Subdocuments.Expanded = True
    $oWordApp.Activewindow.View.ShowRevisionsAndComments = False
    $oWordApp.Activewindow.View.Type = 3
    
    ; delete PDF file
    FileDelete($PDFverzeichnis & " " & $InName & ".PDF")
    
    ; print document
    _WordDocPrint($oDoc,0,1,-1,1,$PDFDrucker,0,"","","",0,0)
    If @error then _ShowError("_WordDocPrint Error")
    
    ; close document, don't save changes
    _WordDocClose($oDoc,0)
    If @error then _ShowError("_WordDocClose Error")
    
    ; close MS Word application
    If Not $WordExists Then _WordQuit($oWordApp)
    If @error then _ShowError("WordQuit Error")

EndFunc

I have several documents that print fine. But one document with 174 pages gets the page numbering wrong. EVERY page has "page 2 of 174".

The only difference to the other docs is that this is a master document with one subdocument.

The document prints fine when I do it manually.

What can I do to force page numbering?

I'm running AutoIt 3.3 on Windows XP with Word 2002 GERMAN.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites



After rearranging the function everything is now working fine

Func _Word2PDF($File)
    
    $oWordApp = _WordCreate($File)
    If @error <> 0 then _ShowError("_WordCreate Fehler")
    
    $oDoc = _WordDocGetCollection ($oWordApp, 0)
    If @error <> 0 then _ShowError("_WordDocGetCollection Fehler")
    
    $oWordApp.Options.WarnBeforeSavingPrintingSendingMarkup = False
    $oWordApp.Options.UpdateLinksAtOpen = False
    $oWordApp.Activedocument.Subdocuments.Expanded = True
    $oWordApp.Activewindow.View.ShowRevisionsAndComments = False
    $oWordApp.Activewindow.View.Type = 3

    _WordDocPrint($oDoc,0,1,-1,1,$PDFDrucker)
    If @error <> 0 then _ShowError("_WordDocPrint Fehler")
    
    _WordDocClose($oDoc,0)
    If @error <> 0 then _ShowError("_WordDocClose Fehler")
    
    _WordQuit($oWordApp)
    If @error <> 0 then _ShowError("WordQuit Fehler")

EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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