Jump to content
Sign in to follow this  
StenchBlossoms

Find and Replace in Word

Recommended Posts

StenchBlossoms

Hi guys,

Recently starting to use AutoIt and I'm trying to fill in a form I have which in .doc format.

I've tried the following so far but I'm not getting any postive results.

#NoTrayIcon
#include<Word.au3>

$formName = "\form.doc"

$word = ObjCreate("Word.Application")
$word.visible = True
$word.Documents.open($formName)

$word.Selection.Find.Text = "Name:";
$word.Selection.Find.ClearFormatting();

$word.Selection.Find.Replacement.Text = "Name: John";
$word.Selection.Find.Replacement.ClearFormatting();

$word.Selection.Find.Forward = true;
$word.Selection.Find.Execute

Would anyone be able to help? Link to examples of this? I've already looked through the help documents but haven't found anything similar.

Thanks

Share this post


Link to post
Share on other sites
SAG

Check the Word management UDF functions in the AutoIt Help files.

In your example, it might look like this:

#include <Word.au3> 

$oWordApp = _WordCreate("", 0, 0)

$oWord = _WordDocOpen($oWordApp, $formName)  

_WordDocFindReplace($oWord, "Name:", "Name: John")

_WordDocSave($oWord)

_WordDocClose($oWord)

_WordQuit($oWordApp)

Edit: made example more complete

Edited by SAG

Share this post


Link to post
Share on other sites
StenchBlossoms

Check the Word management UDF functions in the AutoIt Help files.

In your example, it might look like this:

#include <Word.au3> 

$oWordApp = _WordCreate("", 0, 0)

$oWord = _WordDocOpen($oWordApp, $formName)  

_WordDocFindReplace($oWord, "Name:", "Name: John")

_WordDocSave($oWord)

_WordDocClose($oWord)

_WordQuit($oWordApp)

Edit: made example more complete

Thank you. I will try this.

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  

×