Jump to content
Sign in to follow this  
RajASP

_WordDocOpen Error

Recommended Posts

RajASP

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
RajASP

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
RajASP

Uh.. I don't get how it's related, but this is what I get:

>"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "D:VachanaReportsReport Generator.au3"    
>Exit code: 0    Time: 3.163

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
RajASP

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

Share this post


Link to post
Share on other sites
RajASP

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
RajASP

It says my AutoIt Version is 3.3.6.1

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
RajASP

Nope. My script crashes. :

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  

×