Sign in to follow this  
Followers 0
pdm

WordEx needs sync when Word is visible

14 posts in this topic

I'm using WordEx 1.3 with AutoIt 3.3.8.1, Word 2010, Win 7/64 on a core i5-machine.

When i run the following code, i do get what i expect for now: Just a copy of my Template file stored under a different name.

#include <..\WordEX\WordEx.au3>

const $ERR_NONE   = 0
const $ERR_NOWORD = 1001
const $ERR_NOTPL  = 1002
const $ERR_NOOUT  = 1003
const $ERR_NOCMD  = 1004
const $ERR_INCMD  = 1005

func l_createtpl_cmd ($arg_tpl, $arg_out, $arg_cmd, $arg_vis)
    local $err, $oWord1App, $oDoc1

    $err = $ERR_NONE
    $oWord1App = _Word_Create ($arg_vis, true)
    If @error = 0 Then
        $oDoc1 = _Word_DocAdd ($oWord1App, $wdNewBlankDocument, $arg_tpl, false)
        If @error = 0 Then
            ;work on it
            
            ;save the result
            msgbox (0, "WordTest", "save as "& $arg_out, 0)
            _Word_DocSaveAs ($oDoc1, $arg_out, $wdFormatTemplate)
            if @error <> 0 Then
                $err = $ERR_NOOUT
            endif
        else
            $err = $ERR_NOTPL
        endif
        _Word_Quit ($oWord1App)
    else
        $err = $ERR_NOWORD
    endif
    return $err
endfunc

l_createtpl_cmd (@ScriptDir &"\test.dot", @ScriptDir &"\out.dot", "any command", true

When i take the MessageBox away or answer it before the Word-Document appears, the Word_DocSaveAs function tells me that it was not successfull.

If Word runs invisible, the timimg of my operations seems to be alright.

Is there a way to tell WordEx to synchronize with it's Word-Window or is WinWaitActive the only workaround?

Please give me some advice...

Share this post


Link to post
Share on other sites



I once had a problem with a badly written add-in.

Could you please deactivate your add-ins and try again?


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

Thanks, water,

but i have no active Add-Ins...

Share this post


Link to post
Share on other sites

Which version of Word do you run?


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'm using Word 2010 (as written in the first posting)

Share this post


Link to post
Share on other sites

By the way, my template-file contains a linked picture which is located on a network drive. This is rather slow from my HomeOffice. That is why it takes so long to open up.

But this may not lead to an error, since this could always happen in the production environment.

How can i test the existence of the displayed document?

WinWait doesn't work since the Word-Window is already visible, but not the contents of the copied template file.

IsObj ($oDoc1) returns true after _Word_DocAdd, but i found no property to test the ready state. All attempts referencing properties with $oDoc1 lead to Errors aborting AutoIt.

If i wait long enough to let the contents appear, $oDoc1 works as expected without reloading it!

The object seems to be updated with the appearance of the Document content.

Share this post


Link to post
Share on other sites

Could you create a template without the picture so we know the picture causes the problem?


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'm using Word 2010 (as written in the first posting)

Sorry, missed that :oops:


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 removed the picture from the template so it loads much faster and my example works so far, like it does with an invisible word-window.

But this doesn't solve the timing problem when there actually are references to external objects.

I had similiar problems with the Standard Word.au3.

Of course i can turn the window invisible while loading the template and turn it on whenever i need some optical feedback for testing purposes.

But when can i turn it back on without running into the same errors?

Ok, while testing, i can insert some sleep-statements. But i'm not really happy when things depend on weak timings.

Share this post


Link to post
Share on other sites

I changed the code to load the template invisible and turning the visibility on afterwards:

#include <..\WordEX\WordEx.au3>
#include <array.au3>

const $TITLE = "CheckWord"

const $ERR_NONE   = 0
const $ERR_NOWORD = 1001
const $ERR_NOTPL  = 1002
const $ERR_NOOUT  = 1003
const $ERR_NOCMD  = 1004
const $ERR_INCMD  = 1005

func _msg ($msg, $to = 0)
    msgbox (0, $TITLE, $msg, $to)
EndFunc


func _con ($txt, $eol = @CRLF)
    ConsoleWrite ($txt & $eol)
    ;_msg ($txt & $eol, 1)
EndFunc

#include <..\WordEX\WordEx.au3>
#include <array.au3>

const $TITLE = "CheckWord"

const $ERR_NONE   = 0
const $ERR_NOWORD = 1001
const $ERR_NOTPL  = 1002
const $ERR_NOOUT  = 1003
const $ERR_NOCMD  = 1004
const $ERR_INCMD  = 1005

func _msg ($msg, $to = 0)
    msgbox (0, $TITLE, $msg, $to)
EndFunc


func _con ($txt, $eol = @CRLF)
    ConsoleWrite ($txt & $eol)
    ;_msg ($txt & $eol, 1)
EndFunc

func l_createtpl_cmd ($arg_tpl, $arg_out, $arg_cmd, $arg_vis)
    local $err, $oWord1App, $oDoc1

    $err = $ERR_NONE
    $oWord1App = _Word_Create (0, true)
    If @error = 0 Then
        $oDoc1 = _Word_DocAdd ($oWord1App, $wdNewBlankDocument, $arg_tpl, false)
        If @error = 0 Then
            if $arg_vis then
                sleep (500)
                $oWord1App.visible = $arg_vis
            endif
            ;work on it
            
            ;save the result
            ;_msg ("save as "& $arg_out &"...caption=<"& $oWord1App.caption &"> err="& @error &", ext="& @extended)
            _Word_DocSaveAs ($oDoc1, $arg_out, $wdFormatTemplate)
            if @error <> 0 Then
                $err = $ERR_NOOUT
            endif
        else
            $err = $ERR_NOTPL
        endif
        _Word_Quit ($oWord1App)
    else
        $err = $ERR_NOWORD
    endif
    return $err
endfunc

exit l_createtpl_cmd (@ScriptDir &"\test.dot", @ScriptDir &"\out.dot", "any command", true)

and this runs so far. When there are problems i will vary the value of the sleep-statement.

As stated above, i'm not completly happy with it, but i can go on...

Thank you, water, for thinking it through!

Share this post


Link to post
Share on other sites

Next I would check if we can list the picture objects and wait until the picture has loaded.

While 1
    For $oInlineShape In $oDoc.InlineShapes
        ; Don't know which property to check right now. Maybe $oInlineShape.LinkFormat.SourceName or something similar.
        If $oInlineShape.LinkFormat.SourceName = "xxx" Then ExitLoop 2
        Sleep(100)
    Next
WEnd

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

Or maybe property $oDoc1.AttachedTemplate is only set when the template has successfuuly been loaded.


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

Sorry, water, it only shows

Error: The requested action with this object has failed.

Right after _Word_DocAdd, the property $oDoc1.AttachedTemplate returns an empty string, but after a while the property seems to disappear and lead to the error written above.

Seems to be a very strange behaviour!

Share this post


Link to post
Share on other sites

Will need to test.

But as I'm on vacation quite soon it will take some time ... :)


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

  • Similar Content

    • water
      By water
      New versions of Microsoft Office have been released since the last changes were made to the Word UDF. New file types and new functions need to be supported.
      This updated version supports Word 2003 up to Word 2010. The latest version of AutoIt is needed to use the latest COM error handler.
      Some rarely used functionality has been removed, new functions have and will be added.
      The attached PDF shows what's different between Word.au3 and WordEX.au3
      You'll find examples for every function ready to run.

      Please tell me what you think, about missing functions etc.
      2012-07-31 - Version 1.0 - Downloads: 89


      2012-08-23 - Version 1.1 - Downloads: 26

       
      2012-08-26 - Version 1.2 - Downloads: 277

       
      2012-12-29 - Version 1.3 - Downloads: 937

       
      2013-07-28 - This download page is no longer needed - the rewritten Word UDF is now part of the latest beta version!