hogfan Posted January 29, 2013 Share Posted January 29, 2013 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 Link to comment Share on other sites More sharing options...
hogfan Posted January 30, 2013 Author Share Posted January 30, 2013 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 Link to comment Share on other sites More sharing options...
hogfan Posted January 30, 2013 Author Share Posted January 30, 2013 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 Link to comment Share on other sites More sharing options...
water Posted January 30, 2013 Share Posted January 30, 2013 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 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