Jump to content

AutoITx with Excel/VBA


lgodfrey
 Share

Recommended Posts

I noticed that under Tools/References in Excel VBA window, AutoItX3 1.0 Time Library is listed.

My understanding is that checking a reference here is supposed to allow you to reference functions or definitions in the module checked.

I tried checking this and using AUtoITX3 method without a AutoITX3 object modifier, but got an error msg.

So exactly what does checking this reference do?

I'm, Lovin' IT, X

Link to comment
Share on other sites

Hey lgodfrey (nice avatar!)

You are correct in that checking the box does add a reference to AutoIt into your project, but you need to create and instantiate an AutoItX3 object.

Try placing this code inside a code module (i.e. NOT a Sheet or 'ThisWorkbook'):

Public Sub TestingAutoIT()

Dim autoItObj As AutoItX3

Set autoItObj = New AutoItX3

With autoItObj

.WinActivate ("A Window Name")

End With

Set autoItObj = Nothing

End Sub

VBA will now recognize the methods and properties when you reference autoItObj within the TestingAutoIT sub. Functions can be easily accesed within the "With...End With" statements by typing a period and letting intellisense do all the looking up for you. Now if it could just do my taxes...

One caveat I've found when using AutoIt from VBA: Win functions can get a little messy. I don't know if it's the way VBA is compiled, but it seems as though focus can sometimes get passed BACK to VBA when the script is sending keystrokes etc. If anyone knows precisely why this occurs, I'd love to know! I've been able to work around it by ensuring that winActivate is called after any conditonal logic and before the key commands are sent.

I hope this helps you.

Edited by zfisherdrums
Link to comment
Share on other sites

Hey lgodfrey (nice avatar!)

You are correct in that checking the box does add a reference to AutoIt into your project, but you need to create and instantiate an AutoItX3 object.

Try placing this code inside a code module (i.e. NOT a Sheet or 'ThisWorkbook'):

Public Sub TestingAutoIT()

Dim autoItObj As AutoItX3

Set autoItObj = New AutoItX3

With autoItObj

.WinActivate ("A Window Name")

End With

Set autoItObj = Nothing

End Sub

VBA will now recognize the methods and properties when you reference autoItObj within the TestingAutoIT sub. Functions can be easily accesed within the "With...End With" statements by typing a period and letting intellisense do all the looking up for you. Now if it could just do my taxes...

One caveat I've found when using AutoIt from VBA: Win functions can get a little messy. I don't know if it's the way VBA is compiled, but it seems as though focus can sometimes get passed BACK to VBA when the script is sending keystrokes etc. If anyone knows precisely why this occurs, I'd love to know! I've been able to work around it by ensuring that winActivate is called after any conditonal logic and before the key commands are sent.

I hope this helps you.

Thanks for the reply!

I just use

Public oAIX As Object 'in my declarations module

Set oAIX = CreateObject("AutoItX3.Control") 'in my variable definition module (I have pretty big project, so I keep initial variable definitions and other initializations in their own module)

I do not need the reference to AutoITX for this to work, I was just wondering why it is even there if it doesn't seem to do anything or even be needed!

Regards

Larry

I'm, Lovin' IT, X

Link to comment
Share on other sites

  • 1 month later...

I do not need the reference to AutoITX for this to work, I was just wondering why it is even there if it doesn't seem to do anything or even be needed!

lgodfrey, when you do thing like this:

Dim oAIX as Object
Set oAIX = CreateObject("AutoItX3.Control")

it's called 'late binding', in this case your COM system takes all information about the library from Windows registry at time your program runs, so your project doesn't need the reference. On the other hand this code:

Dim autoItObj As AutoItX3
Set autoItObj = New AutoItX3

so-called 'early binding', that means all references are resolved at compile time, that's why you must introduce it in your project. This method is more reliable by the way, as possible errors are detected by the compiler and not by the customer

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
Share on other sites

  • 10 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...