Skip to content

Instantly share code, notes, and snippets.

@erajanraja24
Created April 11, 2016 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erajanraja24/f5c20991270fc974a99fcfbfbf9c3f01 to your computer and use it in GitHub Desktop.
Save erajanraja24/f5c20991270fc974a99fcfbfbf9c3f01 to your computer and use it in GitHub Desktop.
Autoit in Excel VBA
Sub autoit()
'Create and initialize an object
Dim autoit As AutoItX3
Set autoit = New AutoItX3
'Check autoit installation
If IsNull(autoit) Then
MsgBox "Autoit Is Not installed on your machine", vbCritical + vbOKOnly, "Verify"
Exit Sub
End If
'Launch Calculator
autoit.Run "calc.exe", "C:\Windows\System32"
autoit.Sleep "2000"
If autoit.WinExists("Calculator", "") Then
'Click Button "1" and wait for one Second
autoit.ControlClick "Calculator", "", "131"
autoit.Sleep "1000"
'Click Button "+" and wait for one Second
autoit.ControlClick "Calculator", "", "93"
autoit.Sleep "1000"
'Click Button "2" and wait for one Second
autoit.ControlClick "Calculator", "", "132"
autoit.Sleep "1000"
'Click Button "=" and wait for one Second
autoit.ControlClick "Calculator", "", "121"
autoit.Sleep "1000"
'Close the calculator
autoit.WinClose "Calculator", ""
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment