Jump to content

_WordDocOpen Error


Recommended Posts

Hi guys,

I was writing a small script to modify some data in a template and save it as something else for a lab.. forgive my "noobishness" but I don't really know any other language. The template is a .doc file, and the thing is, that the first time I run my script after I make the template, it works. But the second time I open it using _WordDocOpen, it gives the following error:

C:\Program Files\AutoIt3\Include\Word.au3 (458) : ==> The requested action with this object has failed.:
$o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format)
$o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format)^ ERROR

If you need my script, I'll post it, although I don't think the problem is with the script, because I tried _WordDocOpen separately.. didn't work. Please help me..

Link to comment
Share on other sites

What version of AutoIt do you use?

What version of Word do you use?

What version of Windows do you run (32 or 64 bit)?

Can you please post the whole _WordDocOpen statement?

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

I'm using AutoIt V3 (I don't know how to find any further version numbers), Word 2007, 32 bit Windows 7, and here's how I called upon _WordDocOpen:

$oWordApp = _WordCreate ("")
$oDoc = _WordDocOpen ($oWordApp, "RBS.doc", 0, 6, 0, 1, 0)

In the beginning, I had also tried it without any of the optional values.. no difference..

Edit: I saw that most of the user defined commands that came with my installation were compatible with AutoIt 3.2.0.1+

Edited by RajASP
Link to comment
Share on other sites

When you press F5 in SciTE to execute a script you get the following information in the output pane:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:Temptest.au3" /autoit3dir "C:Program Files (x86)AutoIt3" /UserParams

+>17:22:33 Starting AutoIt3Wrapper v.2.0.3.0 Environment(Language:0407 Keyboard:00000407 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64)

>Running AU3Check (1.54.22.0) from:C:Program Files (x86)AutoIt3

+>17:22:33 AU3Check ended.rc:0

>Running:(3.3.8.0):C:Program Files (x86)AutoIt3autoit3.exe "C:Temptest.au3"

->17:22:39 AutoIT3.exe ended.rc:1

>Exit code: 1 Time: 8.328

What do you get?

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

According to the help file you have to specify the whol path to the word document. Just "RBS.doc" is not enough.

_WordDocOpen: "Full path of the document to open (See Remarks)"

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

Thanks for the advice, water. That part helped a lot! :oops: But now it's giving an error with _WordDocSaveAs ... this is the error I receive:

>"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "D:VachanaReportsReport Generator.au3" 
--> Word.au3 Warning from function _WordDocOpen (The specified file does not exist, but we will attempt to create it.)
C:\Program Files\AutoIt3\Include\Word.au3 (566) : ==> The requested action with this object has failed.:
$o_object.SaveAs ($s_FilePath, $i_Format, $f_LockComments, $s_Password, $f_AddToRecentFiles, $s_WritePassword, $f_ReadOnlyRecommended)
$o_object.SaveAs ($s_FilePath, $i_Format, $f_LockComments, $s_Password, $f_AddToRecentFiles, $s_WritePassword, $f_ReadOnlyRecommended)^ ERROR
>Exit code: 1   Time: 33.796

I thought you might want to take a look at how I called the function, so here it is:

_WordDocSaveAs ($oDoc, @DesktopDir & "ReportsRBS" & (1200000+$labno) & " - " & $name & ".doc")

What's my error? I tried using less "&"s and storing the name as a variable, then using the variable instead of using all those "&"s in my script.. but to no result.. I did it like this (all the variables have been declared and assigned values previously):

Func export()
$name=GUICtrlRead($inputname)
$age=GUICtrlRead($inputage)
$sex=GUICtrlRead($combosex)
$regdate=GUICtrlRead($inputregdate)
$refby=GUICtrlRead($inputrefby)
$result=GUICtrlRead($inputresult)
$date=_NowDate()
$labno=RegRead("HKLMSOFTWAREVDL Report Generator", "")
RegWrite("HKLMSOFTWAREVDL Report Generator", "", "REG_SZ", $labno+1)
$filename=((1200000+$labno) & " - " & $name & ".doc")
$oWordApp = _WordCreate ("")
$oDoc = _WordDocOpen ($oWordApp, @ScriptDir & "ReportsTemplatesRBS.doc", 0, 6, 0, 1, 0)
_WordDocFindReplace($oDoc, "ZNX1234", (120000+$labno))
_WordDocFindReplace($oDoc, "ZNX2345", $name)
_WordDocFindReplace($oDoc, "ZNX3456", $age)
_WordDocFindReplace($oDoc, "ZNX4567", $sex)
_WordDocFindReplace($oDoc, "ZNX5678", $regdate)
_WordDocFindReplace($oDoc, "ZNX6789", $refby)
_WordDocFindReplace($oDoc, "ZNX7890", $date)
_WordDocFindReplace($oDoc, "ZNX8901", $result)
_WordDocSaveAs ($oDoc, @DesktopDir & "ReportsRBS" & $filename )
_WordQuit ($oWordApp)
MsgBox(1, "Export Complete", "The file has been exported")
EndFunc
Edited by RajASP
Link to comment
Share on other sites

Uh.. I realised my mistake in my previous post.. but now I tried using the correct path to RBS.doc, and I'm still getting the original error.. the one with _WordDocOpen that says

>"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "D:VachanaReportsReport Generator.au3" 
C:\Program Files\AutoIt3\Include\Word.au3 (458) : ==> The requested action with this object has failed.:
$o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format)
$o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format)^ ERROR
>Exit code: 1   Time: 12.370

What do I do?

Edited by RajASP
Link to comment
Share on other sites

You still use

_WordCreate ("")

This might be a bug.

Could you please run this script so we can check which version of AutoIt you use?

MsgBox(0, "", "AutoIt version: " & @AutoItVersion)

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

If your script now does what you want it to do then I would disregard the message.

You won't see it when the script is compiled to an exe.

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