Jump to content

Recommended Posts

Posted

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)

Posted

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

Posted (edited)

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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 !!!!!!!

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
×
×
  • Create New...