dbaron4

Word script broke with 3.3.14.2

7 posts in this topic

The following script which is supposed to update the Word document file properties (including the calculated page numbers in the document file properties) works in 3.3.12.0 but fails with a COM error in 3.3.14.2. The error I get is 80020006 - Unknown Name:

#include <Word.au3>

$oWordApp = _Word_Create(1)
$oDoc = _Word_DocOpen($oWordApp, "C:\TEMP9\IN\Master - RS15P05 - Notes Summary.docx")
$objErr = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler
$oDoc.Update ; RESULTS IN COM ERROR 80020006 - UNKNOWN NAME
$objErr = 0 ;disable custom error handler
Exit

Func MyErrFunc()
    $hexnum = hex($objErr.number, 8)
    $SQLErr = $objErr.description
    SetError(1)
    $msg = "COM error detected!"                     & @CRLF & @CRLF & _
           "Error description: "    & $objErr.description    & @CRLF & _
           "Error windescription: " & $objErr.windescription & @CRLF & _
           "Error lastdllerror: "   & $objErr.lastdllerror   & @CRLF & _
           "Error scriptline: "     & $objErr.scriptline     & @CRLF & _
           "Error number: "         & $hexnum                & @CRLF & _
           "Error source: "         & $objErr.source         & @CRLF & _
           "Error helpfile: "       & $objErr.helpfile       & @CRLF & _
           "Error helpcontext: "    & $objErr.helpcontext
    MsgBox(16, "Error", $msg)
    If IsObj($oDoc) Then _Word_DocClose($oDoc)
    If IsObj($oWordApp) Then _Word_Quit($oWordApp)
    Exit
EndFunc   ;==>MyErrFunc

Should the Word document file properties be updated (page numbers recalculated) in a different manner?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Which version of Office do you run?

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

I just checked the Word 2010 reference. There is no Update method for the document object. Do you mean the UpdateSummaryProperties method?


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

I checked and I have Word 2013. I tried $oDoc.UpdateSummaryProperties but I then get an error which includes the phrase "command not available on this platform".

Share this post


Link to post
Share on other sites

That's true. On Word 2013 method UpdateSummaryProperties is no longer available.

You could activate the macro recorder in Word, do what you need to do manually, stop the recorder and post the resulting VBA code. Should be easy to translate to AutoIt.


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

I am wondering if the UpdateSummaryProperties method was removed because it is no longer needed. As in the properties are always up to date. I am going to test this.

Share this post


Link to post
Share on other sites

I am posting the resolution to my problem. This code does the job for me:

;            $oDoc.Update
;            Sleep(2000)

            For $oSR in $oDoc.StoryRanges
                $oSR.Fields.Update
            Next
            Sleep(2000)

 

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