MidNiteRider

sample script showing UDF _Word_DocTableWrite not working

3 posts in this topic

#1 ·  Posted

within the AutoIt Help (v.3.3.14.2), there is an example script showing how to use UDF _Word_DocTableWrite, (shown here):

>>>>>

#include <MsgBoxConstants.au3>
#include <Word.au3>

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableWrite Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableWrite Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Write the content of a 0-based two dimensional array to a Word table
; *****************************************************************************
Local $asArray[3][3] = [[1, 2, 3], ["a", "b", "c"], ["x", "y", "z"]]
Local $oRange = _Word_DocRangeSet($oDoc, -2)
_Word_DocTableWrite($oRange, $asArray, 0)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableWrite Example", _
        "Error creating the table." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocTableWrite Example", _
        "Table successfully added to the end of the document.")

<<<<<

When running this on my machine (Windows 7 Pro and Word 2016), the script returns the following error box:

Error creating the table.     @error = 3, @extended = -2147352567

Apparently, within the UDF, an attempt to set the .Text value for the object range is passing back this strange error code.

$oRange.Text = $sData

I seem to recall similar Office Automation COM error in the past, but don't recall what caused it or the solution.  Anyone have any idea or suggestions on getting past this error?

Share this post


Link to post
Share on other sites



#2 ·  Posted

NEVER MIND!  Further investigation reveals that the example script opens the word doc as readonly (using Word_DocOpen UDF), and if you make a modified version of the script to not open as read only, this error disappears.

; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Extras\Test.doc", Default, Default, True)

Changing the last passed parameter from True to False causes the issue to go away.

Not sure of this error is a side effect of Word 2016, or if the setting of the .Text value fails on a read-only file in previous versions of Word also.

Anyways, I understand why the example open the test doc as read-only, was just a bit confusing as all other examples I have tried worked perfectly without any changes.

Share this post


Link to post
Share on other sites

#3 ·  Posted

IIRC I have already fixed this bug in the next beta version of 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

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