Jump to content
Davgop

Error using Autoit through VBA

Recommended Posts

I am trying to use Autoit was based on this website instructions I have installed Autoit added the reference in VBA. But when i run code it gives me an error as  "Class Not Registered" I am using office 365 with windows 10.

The error occurs in the line where i set the object.

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

Share this post


Link to post
Share on other sites

Earthshine - Thank you for your response.

I am very new to programming, so basically I am working on an automation project to open a URL, login with the credentials, navigate to the specific page and click the print button. I am using VBA with selenium binding and chrome browser.

Now, after I click the print button in the webpage the print option of chrome browser pops-up. All I need to do now is click the print button, but with VBA or Selenium I unable to attain my results.

I learnt that using Auotit I can automate click function. so I was trying the example  given.

It would really helpful if you give any advice or show me the direction. 

Share this post


Link to post
Share on other sites

UIAutomation suits your needs well I should think, and will work, if done properly. There is a lot to learn, certainly. You can post your script here for help in develop/debug

also read this as well;

https://www.autoitscript.com/wiki/FAQ#How_can_I_control_.28click.2C_edit_etc.29_an_external_.28html.29_application.3F

between those two links in this thread, that should get you going. post in the support forum with your scripts if you need help

@junkew's UDF has samples of automating Notepad, as does @LarsJ's UDF, I believe.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

@Earthshine
I have gone through the Links you provided, however I lack the knowledge of the understanding the concepts. I have to say I am a beginner and I do not have programming/development background.

So what I am doing now is, with the code below I am opening up chrome and visiting google.com.

what I want to do is use sendkeys option to press "ctrl+P" and then click the "Print" button. Could you please assist me on the same.

Here is the code:

Sub Test()
Dim bot As New WebDriver, keys As New Selenium.keys
bot.Start "chrome"
bot.Get "https://google.com"
'code needed for "ctrl+P"

End Sub

I am using VBA and selenium
 

Edited by Davgop

Share this post


Link to post
Share on other sites

oh, you may be able to use the AutoItX dll. hang on, there was something about this earlier in the forums. read the help file about AutoItX, you should be able to use that from VBA

what are you using to develop in? you need to set a reference in you vb stuff to that AutoItx DLL file to use the stuff it contains. in your case you may just need to have it local to your running script... i don't use it

 

see this thread

 

I am wondering what this is actually for? I seriously hope you have read the forum rules at this point. 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

@Earthshine - Here is the code I tried but I am getting an error. 

Sub Test()
Dim bot As New WebDriver, keys As New Selenium.keys
bot.Start "chrome"
bot.Get "https://google.com"

AutoItX.send ("{^p}") 'getting error on this line

End Sub

 

image.png.d3182093b4ca1b6ecad7d9707cb24b8a.png

image.png

Share this post


Link to post
Share on other sites

@Earthshine
I apologize for not answering your question in the previous comment. So as I stated in my earlier comment I am running a automation project where it will open up a browser and goes to a specific URL (I cannot share this URL as it is against my company rules) and login with the user credentials, navigates to a specific page and clicks on the button which says print. so after this the chrome Print properties option gets displayed and I need to click the Print option. This is manually task we do on daily basis once the document id downloaded we need to upload it in our data base. All these portals are IP restricted and can only be used through company's IP.

Also, yes I have gone through the Forum rule. I am not doing anything which is illegal or bypassing the terms and conditions. I have created many automation projects using VBA and selenium and this is first time I am facing this task.

I believe that I have answered your question, please do let me know if you need anything else.

Share this post


Link to post
Share on other sites

I am also using Office 365 and it does allows VBA in excel

Edited by Davgop

Share this post


Link to post
Share on other sites

@TheXman -  I am afraid I did not do that, could you please let me know how to do it.
If you are referring to add the reference in VBA (see screenshot below) yes I did that.

image.png.a885fe65e84e8db93f1061758d57b4b7.png

Share this post


Link to post
Share on other sites

Go to your AutoIt installation directory and then go to the AutoItX folder within it.  There you will find the AutoItx.chm help file.  Spend some time learning and understanding how to use AutoItX.  I would suggest getting the examples, in the AutoItX\Examples\VBScript folder, working before moving forward.  Then you will at least know that everything is registered and working properly before trying to move forward with your current issue.

The answer to your specific question can be found under the "COM Interface" topic in that help file.

Share this post


Link to post
Share on other sites

@TheXman - Thanks for your help.
I have registered using the below guide.
image.thumb.png.8c32978f87803c00c5021eaac3b2b382.png

It was successful registered. so now I tried the example in the help file but still getting the same error.
 

Sub Test()
Set oAutoIt = WScript.CreateObject("AutoItX3.Control") 'getting error on this line
oAutoIt.Run ("notepad.exe")
End Sub

dll.png.cc0e8954b85cf580b62533969a0bb107.png

Share this post


Link to post
Share on other sites

You are obviously running a 64bit version of Windows.  Therefore, you most likely need to register the 64bit DLL, AutoItX3_x64.dll.

Edited by TheXman

Share this post


Link to post
Share on other sites

Now that you have registered the DLLs, what happens when you run either of the vbscript examples in the Examples folder that I referenced?  If it is an error in a MsgBox, then show the MsgBox.

Edited by TheXman

Share this post


Link to post
Share on other sites

@TheXman - Here is the error message. 
 

Sub Test()
Set oAutoIt = WScript.CreateObject("AutoItX3.Control") 'getting error on this line
oAutoIt.Run ("notepad.exe")
End Sub

image.png.325e15fdbc75f2445c8d3dfdb2a58c5f.png

Share this post


Link to post
Share on other sites

That is NOT one of the examples in the folder.     Double-click one of the example vbs files and show me the error.

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

×
×
  • Create New...