Sign in to follow this  
Followers 0
VeryNew

Help with GUI / Variables / find and replace

5 posts in this topic

I am very new to autoit, but really enjoy using it. So far i have searched the forums and the help files but I am so new to this that I need to ask...

Currently i am trying to do the following:

Have a GUI input box that collects my data as variables. The variables are then inputed into a word document replacing the existing text and printing and then saving the word document to another variable. The purpose of what I want to do is streamline writing letters (the body of the letters are the same - the variables are the only items that change).

For example: I want an input box that I input the Name, Address, Cost, and Filename - then the name and address etc are "saved" as variables. The word document is opened and the "name" and "address" etc are replaced by the variables. The word document is then saved as another variable and the letter is printed, the word document closes.

I have written a newbie "program" with the combination of .bat files and autoit, however i can only do it with individual input boxes and using keyboard shortcuts to find and replace (like ctrl h).

I know there is a much more streamlined way of doing this, but so far I only got as far (using autoit only) as having the template letter (in a text file because the word document didnt work) find and replace only 1 variable with "numbers" instead of the actual text.

I guess i m looking for an example of how this will work, I appreciate any help and guidance offered.

Share this post


Link to post
Share on other sites



Hello VeryNew,

you could take a look at _WordDocFindReplace in the helpfile. Along with that there are a bunch of _Word* functions implemented, that should do the trick.

Regards,

Hannes

;)

P.S. Welcome to AutoIT. :)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Hello VeryNew,

you could take a look at _WordDocFindReplace in the helpfile. Along with that there are a bunch of _Word* functions implemented, that should do the trick.

Regards,

Hannes

;)

P.S. Welcome to AutoIT. :)

Thank you.

I am still having the problem where the text in word that is replaced is replaced with a number (in this case its a 4), instead of the text I typed in the input field. I think that i do not have the GUI input boxes correct (among other things). I have 8 variables that i am trying to set, in the gui window, but i dont know how to "save" the variables so i can use them later. Do i have to save the variables to a seperate text file for later use (when i say later use i just mean save multiple variables or inputs,)?

Basically I have:

The word document has the following text that needs to be found and replaced by my input:

$name

$address

$jobname

etc...

I set the gui window to set the above variables (labeled the same)

I then am using the following:

---------------------------------------------------------------------------------

GUICtrlRead( $contractor )

$oFind = _WordDocFindReplace($oDoc, "$contractor", $contractor )

If $oFind Then

MsgBox(0, "FindReplace", "Found and replaced.")

Else

MsgBox(0, "FindReplace", "Not Found")

EndIf

exit

-------------------------------------------------------------------------------------

But the "$contractor" that is found is replaced with the number "4" instead of the name I typed into the input box.

Share this post


Link to post
Share on other sites

Word actually has this built in (called mail merge). I have no idea exactly what you want, but I'd have a look at it and see if it's a viable alternative. It may be that you don't want to do it like that

Tools -> Letters and mailings -> Mail merge

Share this post


Link to post
Share on other sites

But the "$contractor" that is found is replaced with the number "4" instead of the name I typed into the input box.

As expected. See helpfile for how to use GUICtrlRead().

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