Jump to content
Sign in to follow this  
hogfan

Error using _WordDocReplace.......

Recommended Posts

hogfan

I am having some trouble understanding where my formatting is wrong in this code, specifically with the _WordDocFindReplace parameters:

;Open the letter template and fill out the form
Local $myTemplate = @ScriptDir & "\templates\ Letter.doc"

Local $oWordApp  = _WordCreate("", 0, 0)
Local $oDoc = _WordDocOpen($oWordApp, $myTemplate)

Local $oFind = _WordDocFindReplace($oDoc, "[TN]", $EspStatTN)
Local $oFind = _WordDocFindReplace($oDoc, "[USERNAME]", $EspStatUsername)
Local $oFind = _WordDocFindReplace($oDoc, "[PASSWORD]", $EspStatPassword)
Local $oFind = _WordDocFindReplace($oDoc, "[EMAILADDRESS]", $EspStatUsername)
Local $oFind = _WordDocFindReplace($oDoc, "[IPBLOCK]", $EspStatIPBlock)
Local $oFind = _WordDocFindReplace($oDoc, "[NETMASK]", $EspStatNetmask)
Local $oFind = _WordDocFindReplace($oDoc, "[NETMASK]", $EspStatNetmask)


_WordDocSaveAs($oDoc, @ScriptDir & "\Test.doc")
_WordQuit($oWordApp)

At runtime the error is actually occurring within the Word.au3 UDF. I'm not sure why it's saying there is an error in the expression, because I followed the example code here:

http://www.autoitscript.com/autoit3/docs/libfunctions/_WordDocFindReplace.htm

The error returned is:

C:\Program Files\AutoIt3\Include\Word.au3 (749) : ==> Error in expression.:
$return = .Execute($s_FindText, $f_MatchCase, $f_MatchWholeWord, $f_MatchWildcards, $f_MatchSoundsLike, $f_MatchAllWordForms, $f_Forward, $i_Wrap, $f_Format, $s_ReplaceWith, $i_Replace)
$return = .Execute($s_FindText, $f_MatchCase, $f_MatchWholeWord, $f_MatchWildcards, $f_MatchSoundsLike, $f_MatchAllWordForms, $f_Forward, $i_Wrap, $f_Format, $s_ReplaceWith, $i_Replace)^ ERROR

Any assistance narrowing down where my error is here is greatly appreciated. Basically, I'm opening an existing document, executing a Find/Replace function to fill out a form, and then saving the resulting file back out.

-hogfan

Share this post


Link to post
Share on other sites
hogfan

Everything is working up until the Find/Replace function. I am trying to Find/Replace in a partially protected word document. It's template where you can tab between the fields. All areas in which I am trying to do a Find/Replace are editable however. I'm really at a loss here because. "Error in Expression" doesn't help me troubleshoot what the problem is. I would at first think that it doesn't like the syntax, but it's exactly the same as in the example.

-hogfan

Share this post


Link to post
Share on other sites
hogfan

Tested with another document and it works, so it looks like the protected document is the problem. Anybody know of a way to fill out the fields of a protected document "behind the scenes" (ie. without using some type of function that just sends keypresses).?

-hogfan

Share this post


Link to post
Share on other sites
water

Why do you think the doucment is proteced? To not allow changes to be made to the document?

Open the document with proper permissions (provide the necessary password at open time) and the error should be gone.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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
Sign in to follow this  

×