MidNiteRider Posted April 21, 2017 Share Posted April 21, 2017 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 More sharing options...
MidNiteRider Posted April 21, 2017 Author Share Posted April 21, 2017 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 More sharing options...
water Posted April 21, 2017 Share Posted April 21, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now