Sign in to follow this  
Followers 0
bshoenhair

How to call AutoItX3 in VBA

14 posts in this topic

VBA may not be everyones choice but it is all I have.

I want to start using AutoItX3 in my VBA applications but I am unable to figure out how to call and utilize AutoItX3.

I am hoping someone will show me a breif example.

Share this post


Link to post
Share on other sites



VBA may not be everyones choice but it is all I have.

I want to start using AutoItX3 in my VBA applications but I am unable to figure out how to call and utilize AutoItX3.

I am hoping someone will show me a breif example.

Here's the head of my emailsaver menu proggy

Keep me posted I love autoit with html

Don't forget to install autoitx

runwait("regsvr32 "&$LocalPath&"\modules\AutoItX.dll /s")

runwait("regsvr32 "&$LocalPath&"\modules\AutoItX3.dll /s")

if anyone knows a vbscript way of doing that let me know

Rick

1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">

<TITLE>Save WebEmail Menu by Kirkham Ver 3</TITLE>

<META NAME="GENERATOR" CONTENT="StarOffice 7 (Win32)">

<META NAME="CREATED" CONTENT="20040508;9575215">

<META NAME="CHANGEDBY" CONTENT="James Kirkham">

<META NAME="CHANGED" CONTENT="20040531;9571350">

<script LANGUAGE="VBScript">

<!--

Set oAutoIt = CreateObject("AutoItX.Control")

Set oAutoIt3 = CreateObject("AutoItX3.Control")

localpath = oAutoIt.IniRead (".\rkcontrol.ini", "Paths", "localpath")

'localpath = ""

'MsgBox "The localpath is " & localpath

'oAutoIt3.IniWrite localpath&"\modules\rkcontrol.ini", "textpath", "ChangeSavePaths","No"

oAutoIt3.IniWrite localpath&"\modules\rkcontrol.ini", "textpath", "Run","Blank"

'savepath = oAutoIt.IniRead (localpath&"\modules\rkcontrol.ini", "textpath", "Command",TheForm.textpath.Value)

var=oAutoIt3.WinSetOnTop ( "Save WebEmail Menu by Kirkham Ver 3", "", 1)

Sub Submit_onclick

Dim TheForm

dim textpath

Set TheForm = document.ValidForm

'var=oAutoIt.Iniwrite(mainpath&"\modules\rkcontrol.ini", "Time", "SecondsTarget",TheForm.sec.Value)

'MsgBox "The mainpath is " & localpath & TheForm.textpath.Value

for each x in document.ValidForm("textpath")

if x.checked then

oAutoIt3.IniWrite localpath&"\modules\rkcontrol.ini", "textpath", "Run",x.value

exit for

end if

next

' oAutoIt.Iniwrite localpath&"\modules\rkcontrol.ini", "textpath", "Run",TheForm.textpath.Value

savepath=oAutoIt3.IniRead (localpath&"\modules\rkcontrol.ini", "textpath", "Run","Blank")

changepaths = oAutoIt3.IniRead (localpath&"\modules\rkcontrol.ini", "textpath", "ChangeSavePaths","" )

if not (savepath = "Blank" or savepath ="") then

if not (changepaths="Yes") then

'MsgBox "The savepath is " & savepath

oldtitle = oAutoIt.WinGetActiveTitle()

var=oAutoIt.WinSetTitle(oldtitle, "", "Get Path by Kirkham "&savepath)

oldtitle = oAutoIt.WinGetActiveTitle()

oAutoIt.WinMinimize oldtitle, ""

'oAutoIt.sleep 2000

oAutoIt.ClipPut ""

'oAutoIt.Send "^a"

'oAutoIt.sleep 1000

'oAutoIt.Send "^c"

oAutoit3.runwait localpath&"\modules\GetText.exe",""

oAutoIt.WinRestore oldtitle, ""

var=oAutoIt.WinSetTitle(oldtitle, "","Save WebEmail Menu by Kirkham Ver 3")

'winwait("Save WebEmail Menu by Kirkham Ver 3","")

'winactivate("Save WebEmail Menu by Kirkham Ver 3","")

'oAutoit3.send("{f5}")

end if

end if

End Sub

sub DeletePaths_onclick

oAutoit.ClipPut("")

oAutoit.sleep 1000

oAutoit.ClipPut(document.PathForm.SavePathsFile.Value)

oAutoIt3.IniWrite localpath&"\modules\rkcontrol.ini", "textpath", "ChangeSavePaths","Yes"

changepaths = oAutoIt3.Iniread (localpath&"\modules\rkcontrol.ini", "textpath", "ChangeSavePaths","No")

'MsgBox "Changepaths is " & changepaths

oAutoit3.runwait localpath&"\modules\DeletePaths.exe",""

'oAutoit.sleep 3000

'oAutoit.winclose "Save WebEmail Menu by Kirkham Ver 3",""

'oAutoit.winwaitclose "Save WebEmail Menu by Kirkham Ver 3",""

end sub

-->

</SCRIPT>


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

Thank You for the example.

Share this post


Link to post
Share on other sites

Hi tutor2000/Posters

BY

Don't forget to install autoitx

runwait("regsvr32 "&$LocalPath&"\modules\AutoItX.dll /s")

runwait("regsvr32 "&$LocalPath&"\modules\AutoItX3.dll /s")

do you mean run an AutoIT script with those lines?

Do you have to run these lines every time you want to use AutoITX in your app (like VBA).(I'm stuck with VBA too, same as bshoenhair)

***********

JdeB gave me the link to AutoITX since the one on the download section dead ends

but the files there do not mention AutoITX3. What is this file?

The files at this link also have 9 files in VC6.zip.....what do I do with these?

**********

Is AutoITX stable enough now for relative novices to use?

:D

Larry


I'm, Lovin' IT, X

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In the directory i mention you'le find the AutoitX3.dll.

You need to register it before you can use it in VB so need to do this command from the command prompt:

regsvr32 path-to-the-file\AutoItX.dll

Now you are ready to go...

The Methods.txt describes all the available commands ....

forget about the VC6.zip unless you are interested in the C stuff

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

In the directory i mention you'le find the AutoitX3.dll.

You need to register it before you can use it in VB so need to do this command from the command prompt:

regsvr32 path-to-the-file\AutoItX.dll   

Now you are ready to go...

The Methods.txt describes all the available commands ....

forget about the VC6.zip unless you are interested in the C stuff

I'm still trying to find a vbs way to install it so I don't have to start with a compiled script that starts the hta menu

Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

I'm still trying to find a vbs way to install it so I don't have to start with a compiled script that starts the hta menu

Not sure i understand ...

Do you mean to do the regsvr32 command ?


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

THanks for the multiple inputs. It seems to have registered with me, and my first test worked great. :D

For other script/AutoIT newbies, this is what I did (you pros can stop reading!)

1) downloaded autoITX3.dll from

http://www.autoitscript.com/autoit3/files/unstable/autoitx/

Put it in a permanent directory in my file system (I put mine in C:\Utility\AutoIT\AUtoITX3\)

2) went to Windows Start button, to RUN, browsed to the AutoITX3.dll file and enter to get the path, then typed "regsvr32 " with a space in front of the path\file, press enter. A msg Window poped up (WXP at least) telling me it "installed" successfully.

As Tutor2000 said, "Now you are ready to go..."

3) Here is a simple test code I did for Excel 2003 VBA. It tells Excel VBA to link up with AutoITX3, and then uses AutoITX3 commands to perform a simple operation on a window. note you have to prefix the standard AutoIT type command with whatever name you gave the AutoITX3 object module.

Option Explicit

Sub autoitx3_test()  'quick AutoITX3 test for Excel 2003 VBA to find Window "#1 and put some text into a field (into a "Button" as AutoIT Window Spy calls it)

Dim oAutoIT As Object               
Set oAutoIT = CreateObject("AutoItX3.Control")   'Set "Link" to AutoITX3, don't forget the "3", missing in some of the posts

Dim iError_Return1 As Integer
Dim iError_Return2 As Integer

iError_Return1 = oAutoIT.WinWaitActive("#1", "sometext", 1)         'turn focus to window with name begining #1, with sometext in it.  Time out is only 1 sec...I want things to happen fast!

iError_Return2 = oAutoIT.ControlSetText("#1", "sometext", "Edit2", "2000") 'Put "2000" in Edit2 window "button" of #1 window.

Stop  'this stop stops execution and goes to debug mode so you can go look at error codes.

End Sub

Obviously in real code you will want to add error trapping to monitor the return values for successfull operations, but the stop command will let you do that quickly in this test.

The list of available commands is in the text file at the link above. You have to use your VBA built in functions to perform things like string maniptlation....looks like AutoITX3 concentrates on adding Windows manipulation/functionality to your your program such as VBA, and does not try to "interfere" with "normal" functions...this make sense to me because the true strength of AutoIT seems to be the abiliity to add stable windows manipulation, avoiding the pitfalls of things like "SendKeys".

Edited by lgodfrey

I'm, Lovin' IT, X

Share this post


Link to post
Share on other sites

looks like AutoITX3 concentrates on adding Windows manipulation/functionality

And then some

Nice code btw I'm still learning vbs myself and love it with autoitx.

This is from the methods.txt you got with autoitx

Rick

AutoItSetOption ( "option", param )

BlockInput ( flag )

CDTray ( "drive", "status" )

ClipGet ( )

ClipPut ( "value" )

ControlClick ( "title", "text", "classnameNN" [, button] [, clicks]] )

ControlCommand ( "title", "text", "classnameNN", "command", "option" )

ControlDisable ( "title", "text", "classnameNN")

ControlEnable ( "title", "text", "classnameNN" )

ControlFocus ( "title", "text", "classnameNN" )

ControlGetFocus ( "title" [, "text"] )

ControlGetPosX ( "title", "text", "classnameNN" )

ControlGetPosY ( "title", "text", "classnameNN" )

ControlGetPosHeight ( "title", "text", "classnameNN" )

ControlGetPosWidth ( "title", "text", "classnameNN" )

ControlGetText ( "title", "text", "classnameNN" )

ControlHide ( "title", "text", "classnameNN" )

ControlMove ( "title", "text", "classnameNN", x, y [, width [, height]] )

ControlSend ( "title", "text", "classnameNN", "string" [, flag] )

ControlSetText ( "title", "text", "classnameNN", "new text" )

ControlShow ( "title", "text", "classnameNN" )

IniDelete ( "filename", "section", "key" )

IniRead ( "filename", "section", "key", "default" )

IniWrite ( "filename", "section", "key", "value" )

IsAdmin ( )

MouseClick ( "button" [, x, y [, clicks [, speed ]]] )

MouseClickDrag ( "button", x1, y1, x2, y2 [,speed] )

MouseDown ( "button" )

MouseGetCursor ( )

MouseGetPosX ( )

MouseGetPosY ( )

MouseMove ( x, y [, speed] )

MouseUp ( "button" )

Opt( "option", param )

PixelGetColor ( x , y )

PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )

ProcessClose ( "process" )

ProcessExists ( "process" )

ProcessWait ( "process" [, timeout] )

ProcessWaitClose ( "process" [, timeout] )

RegDeleteKey ( "keyname" )

RegDeleteVal ( "keyname", ["valuename"] )

RegRead ( "keyname", "valuename" )

RegWrite ( "keyname", "valuename", "type", "value" ) // Type is REG__SZ, REG_DWORD, etc.

Run ( "filename" [, "workingdir" [, flag]] )

RunAsSet ( ["user", "domain", "password"] )

RunWait ( "filename" [, "workingdir" [, flag]] )

Send ( "keys" [, flag] )

Shutdown ( code )

Sleep ( delay )

StatusbarGetText ( "title" [, "text" [, part]] )

ToolTip ( "text" [, x, y] )

URLDownloadToFile ( "URL", "filename" )


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi Tutor2000

(Is that the 19th or 20th century?????? I never understood that debate, seems obvious that as soon as you are born you are in your first year, so as soon as 2000 ticks over we are in the 20th :D )

RE

"finding a VBS way to install",

you probably already saw the RegisterXLL method and the RegisteredFunctions Property that are available in MS OFFICE and they do not fit your needs)

RE strengths of AutoITXL3, by my count it has

-~80% window type maniputlation/functionality,

-plus a few register functions (that I would be scared to use as a home user),

-plus a couple of file commands that are probably a heck of a lot easier to use than VBA equivalents,

-plus some run type commands, again probably easier to use

-plus a sleep command that VBA doesn't have

One nice feature about using AutoITX3 is that you can mix and match with AutoIT...if you want to perform some function serially, use AutoITX3, but if you want to do it asynchronously, run an AutoIT script. Of course it is not ture asynchronously since the processer just spends time on one task and goes back to another, but this is fast enough now adays that it seems that they run in parallel. It is asynchronously as far as your VBA code is concerned though. I am doing this now since I want to continuously data log an instrument data feed, but send warnings or update info to the user. If there is a serious problem, I keep "yelling" (critical.wav) at the user until they do something about the situation. But I need to keep monitoring the data feed while waiting for the response. So I use AutoIT to open message boxes. Have to put in a "DoEVENTS" in the VBA code of course to allow the user to click a button on the msg box.

DoEvents/Sleep is another interesting trade off...one waits a fixed amount of time, the other waits until other activity is complete. With doevents, I can actually browse on-line even though I am monitoring a data feed of 100 events a second.

I'm still learning vbs myself and love it with autoitx.

me too, all self taught as you prbably can tell since I do not know the buzz words very well, like you use vbs, I used vba. (Read between the lines...pls don't roll your eyes too much if I get off base! Or mix and match topics like I did here, I guess some of the comments probably belong in CHAT or somerwhere else, but they all seem related so I kept them together :huh2: )

Regards

Larry

PS would be nice to have the msg box functions added...I find the timer option extremely usefull and a annoying to do your own in VBA.

Edited by lgodfrey

I'm, Lovin' IT, X

Share this post


Link to post
Share on other sites

RE

you probably already saw the RegisterXLL method and the RegisteredFunctions Property that are available in MS OFFICE and they do not fit your needs)

No I did n't where can I find out more about it?

And thanks all your comments and knowledge is truly appreiciated. msgbox with the timer would be great for autoitx

Rick


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

Share this post


Link to post
Share on other sites

Hi Tutor2000,

you probably already saw the RegisterXLL method and the RegisteredFunctions Property that are available in MS OFFICE and they do not fit your needs)

I came accross these when I was looking at what functions were available in AutoITX3 and in Office VBA (Speciifcally Excel). I just did a help search for Register to see if there were any register manipulation functions/commands and saw these instead. They looked like they may be usefull to you, although I do not know why the RegisterXLL has XLL and the RegisteredFunctions Property mentions both XLL and DLL. Do a help search, keyword register, and you should find it.

:D Don't give me too much credit here...I am just a older coot that is learning scripts and vba simultaneously for a special, big, personal project. I am not new to programming, used 3-4 languages hmmm, almost 40 years ago when a mainframe was not as good as my desk top for processing power, dabled in programming and spreadsheets ever since. But I know how intimidating this stuff can be to newbies that don't even have that background to build on, so I KISS for myself and sometimes re-interprete the pros for other newbies.

Good luck with the DLL stuff, it's over my head, I just stick in whatever I'm told like the create object for VBA to link to AutoITX3. I do not understand what it really does.

Regards

Larry


I'm, Lovin' IT, X

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