Jump to content
Sign in to follow this  
zjsong

problem of call autoit in vba

Recommended Posts

zjsong

I need to call autoit function in VBA, here is VBA code:

Sub t()

Set au3 = CreateObject("autoitx3.control")

w = "[CLASS:Notepad]"
au3.WinActivate (w)

Call au3.ControlSetText(w, "", "Edit1", "123") 'OK

h = au3.ControlGetHandle(w, "", "Edit1")
Call au3.ControlSetText(w, "", h, "12345") 'Fail

'MsgBox h

Set au3 = Nothing

End Sub

why can't VBA send handle "h" to autoit correctly ?

Share this post


Link to post
Share on other sites
zjsong

a little idea: the type of h is String, but autoit need Ptr type. so the problem is: how to change h from String to Ptr or Long type? Thanks.

vba code:

Sub t()

Set au3 = CreateObject("autoitx3.control")

w = "[CLASS:Notepad]"
au3.WinActivate (w)

Call au3.ControlSetText(w, "", "Edit1", "123") 'OK

h = au3.ControlGetHandle(w, "", "Edit1")
Call au3.ControlSetText(w, "", h, "12345") 'Fail

ph = VarPtr(h)


MsgBox TypeName(h) & " " & TypeName(ph)

Set au3 = Nothing

End Sub

autoit code:

;Run("notepad.exe")

$w="[CLASS:Notepad]"
WinActivate($w)
$h=ControlGetHandle($w,"","Edit1")
ControlSetText($w,"",$h,"12345")
MsgBox(0,0,$h & " " & VarGetType($h))

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  

×