Jump to content

sample script showing UDF _Word_DocTableWrite not working


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

IIRC I have already fixed this bug in the next beta version of AutoIt.

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