Jump to content

[SOLVED] Wrong Pagenumbers when printing with word.au3


water
 Share

Recommended Posts

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...