Sign in to follow this  
Followers 0
Info

Search for text in an existing word document

4 posts in this topic

I'm having trouble word the _word functions so can anyone help me?

I just want it to return true if the text exists in the document or false if the text does not exist.

Share this post


Link to post
Share on other sites

It can be a little ambiguous - here it is how to do it:

$oWord = _WordCreate("my file with full path", 0, 0) ;hidden
If _WordDocFindReplace($oWord, "my text") Then
    MsgBox(0, "found", "text found")
Else
    MsgBox(0, "not found", "text not found")
EndIf
_WordQuit($oWord)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I'm getting --> Word.au3 Error from function _WordDocFindReplace, $_WordStatus_InvalidObjectType

Share this post


Link to post
Share on other sites

Straight from the help file - you should read that by the way.

*******************************************************
; Example 1 - Create a word window, open a document, find "this", 
;               replace all occurrences with "THIS", quit without saving changes.
; *******************************************************
;
#include <Word.au3>
$oWordApp = _WordCreate (@ScriptDir & "\Test.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oFind = _WordDocFindReplace($oDoc, "this", "THIS")
If $oFind Then
    MsgBox(0, "FindReplace", "Found and replaced.")
Else
    MsgBox(0, "FindReplace", "Not Found")
EndIf
_WordQuit ($oWordApp, 0)

It looks like my first example wasn't working.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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  
Followers 0