Jump to content
Sign in to follow this  
potters

MS Word help - first time trying AutoIt

Recommended Posts

potters

Hi,

I am brand new to programming and AutoIt. I know this is totally stupid, but I am having an issue with a script I am trying to write (just to practice). I can get a blank word doc to open but I can't get the text to send. I've tried a couple of different ways... HELP???

#ce ----------------------------------------------------------------------------

; Script Start

#include <Word.au3>

$oWordApp = _WordCreate ()

$oDoc.Send("The quick brown fox jumps over the lazy dog.")

$oDoc.WinWaitActive

$oDoc.Send = ("The quick brown fox jumps over the lazy dog. {enter}")

$oDoc.WinWaitActive("Untitled-$oWordApp")

$oDoc.WinWaitActive("Untitled-$oWordApp")

$oDoc.Send = ("The quick brown fox jumps over the lazy dog. {enter}")

$oDoc.WinWaitActive("Untitled-$oWordApp")

$oDoc.WinWaitActive("Untitled-$oWordApp")

$oDoc.WinClose("Untitled-$oWordApp")

$oDoc.WinWaitActive("$oWordApp", "Do you want to save")

$oDoc.Send("!n")

_WordQuit ($oWordApp, -1)

Share this post


Link to post
Share on other sites
BillLuvsU

I'm not familiar with word.au3 (I don't use MS Office), but you seem to have several errors in your programming "grammar" (referred to as syntax). I would suggest going through Welcome To AutoIt 1-2-3, it can be found in the examples section of the forum, right at the top (It's a sticky).


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites
water

You are mixing the Word COM object and AutoIt functions. It doesn't work this way.

You create an application object by _WordCreate(). What's needed next is a function call to create the document object ($oDoc). Then you can enter text.

I check if I can find a useful example.

Edit: Something like this should work. If you have problems creating the doc, please try the latest Beta version of AutoIt.

#include <word.au3>
$oWordApp = _WordCreate(@ScriptDir & "\Test.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
$oDoc.Range.InsertAfter("Test Text")
;_WordDocSave($oDoc)
;_WordQuit($oWordApp)
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
JoHanatCent

I agree with all of the above !

To use the OP example:

#include <Word.au3>
Opt("WinWaitDelay", 250)
$oWordApp = _WordCreate("Temp.doc");Create file it is easier for a consistant Title
$yes = 0
While $yes = 0
;Force focus ======== V
$Yes = WinActivate("Temp.doc");<<<< === Make sure this is what you expect in the Title!
Sleep(500); Pause script for A while
wend
Send("The quick brown fox jumps over the lazy dog.")
Send("{enter}")
Sleep(500); Pause script for A while
Send("The quick brown fox jumps over the lazy dog.")
Send("{enter}")
Sleep(500); Pause script for A while
WinClose("Temp.doc");<<<< === Make sure this is what you expect in the Title!
WinWaitActive("Microsoft "); The actual Title not the message !!!!
Send("!n")
_WordQuit($oWordApp, -1); This will produce an error because you already closed the window with WinClose !!!!!!!

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  

×