Jump to content
Sign in to follow this  
dragaron

Trouble using Word Document Functions

Recommended Posts

dragaron

This is just for my own instructional purposes at this point.

Goal: To open an existing word ".doc" on my desktop named "Test.doc", and replace "EEE" with "FFF", add a Return, then save the document. This script runs without errors, but "EEE" is still in the document when I open it after the script is complete - Nothing changed.

Contents of "Test.doc", without the quotes obviously:

"This is just a test. AAA, BBB, CCC, EEE."

Contents of AutoIt Script:

$oWordApp = _WordCreate ("")

$oDoc = _WordDocOpen ($oWordApp, "C:\Documents and Settings\Owner\Desktop\Test.doc")

$oFind = _WordDocFindReplace($oDoc, "EEE", "FFF" & @CRLF)

_WordDocSave ($oDoc)

_WordQuit ($oWordApp)

Share this post


Link to post
Share on other sites
PsaltyDS

This is just for my own instructional purposes at this point.

Goal: To open an existing word ".doc" on my desktop named "Test.doc", and replace "EEE" with "FFF", add a Return, then save the document. This script runs without errors, but "EEE" is still in the document when I open it after the script is complete - Nothing changed.

Contents of "Test.doc", without the quotes obviously:

"This is just a test. AAA, BBB, CCC, EEE."

Contents of AutoIt Script:

$oWordApp = _WordCreate ("")

$oDoc = _WordDocOpen ($oWordApp, "C:\Documents and Settings\Owner\Desktop\Test.doc")

$oFind = _WordDocFindReplace($oDoc, "EEE", "FFF" & @CRLF)

_WordDocSave ($oDoc)

_WordQuit ($oWordApp)

There's no #include. What UDF are you using for the _Word* funcitons? Are there any errors on the SciTE console when you run it?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
GMK

This should work better:

#include <Word.au3>
$oWordApp = _WordCreate ()
$oDoc = _WordDocOpen ($oWordApp, @DesktopDir & "\Test.doc")
$oFind = _WordDocFindReplace($oDoc, "EEE", "FFF" & @CR)
_WordDocSave ($oDoc)
_WordQuit ($oWordApp)

Share this post


Link to post
Share on other sites
big_daddy

This is just an optimized version of GMK's code.

#include <Word.au3>

$oWordApp = _WordCreate(@DesktopDir & "\Test.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
_WordDocFindReplace($oDoc, "EEE", "FFF" & @CR)
_WordDocSave($oDoc)
_WordQuit($oWordApp)

Share this post


Link to post
Share on other sites
dragaron

Thank you everyone. I forgot "#include <Word.au3>". I appreciate the help and am really loving this program.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.