Jump to content

Error using _WordDocReplace.......


hogfan
 Share

Recommended Posts

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

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

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

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