Hello everyone hope all of you have been staying safe
I am trying to automate with Excel VBA an online form filling procedure where we first need to login before updating the online form
To login we have 4 steps
the first is to key in the username
The second is to key in the password
The third is to key in the captcha
And the fourth is to click the login button
Since the captcha is involved I am doing this on a browser that is already open - so that I can key in the captcha into an excel cell and read from there - so I have written the code to access an already open internet explorer using the shell command. And have reached the stage where the first three steps are completed.
But I am not able to click on the login button because the login button is not active.
After a few trials I found that the login button only gets activated if there are 5 characters in the captcha textbox and entered via a keystroke.. at least the last character needs to be entered via a keystroke
So what I am essentially looking for is way to have VBA replicate a mouse click in the textbox so that we have an active html textbox with the cursor blinking in it
Can we do this, please help me.
Am providing the code I have here.
I did a bit of research and learned about SendKeys and using ExcelAPIs but I'm just taking baby steps here and not sure how these work or how to implement these ?.
Looking forward to all the help I can get. Thanks in advance.
I am trying to automate with Excel VBA an online form filling procedure where we first need to login before updating the online form
To login we have 4 steps
the first is to key in the username
The second is to key in the password
The third is to key in the captcha
And the fourth is to click the login button
Since the captcha is involved I am doing this on a browser that is already open - so that I can key in the captcha into an excel cell and read from there - so I have written the code to access an already open internet explorer using the shell command. And have reached the stage where the first three steps are completed.
But I am not able to click on the login button because the login button is not active.
After a few trials I found that the login button only gets activated if there are 5 characters in the captcha textbox and entered via a keystroke.. at least the last character needs to be entered via a keystroke
So what I am essentially looking for is way to have VBA replicate a mouse click in the textbox so that we have an active html textbox with the cursor blinking in it
Can we do this, please help me.
Am providing the code I have here.
VBA Code:
Sub Access_Page()
Dim shellWins As SHDocVw.ShellWindows
Dim IE As New SHDocVw.InternetExplorer
Dim HtmlDoc As MSHTML.IHTMLDocument
Dim ID_box As MSHTML.IHTMLElement, pWrd As MSHTML.IHTMLElement
Dim iCaptcha As MSHTML.HTMLInputElement, iLoginBtn As MSHTML.HTMLInputElement
Dim I_Path As String
Set shellWins = New SHDocVw.ShellWindows
For Each IE In shellWins
If IE.Name = "Internet Explorer" And IE.LocationURL = "website url" Then
Set HtmlDoc = IE.document
Exit For
End If
Next IE
Set ID_box = HtmlDoc.getElementById("txtUsername")
Set pWrd = HtmlDoc.getElementById("txtPassword")
Set iCaptcha = HtmlDoc.getElementById("txtCaptcha")
Set iLoginBtn = HtmlDoc.getElementById("btnSubmit")
ID_box.Value = Range("B2").Value
pWrd.Value = Range("C2").Value
iCaptcha.Value = Range("D2").Value
iLoginBtn.Click
Do while IE.ReadyState <> READYSTATECOMPLETE
DoEvents
Loop
End Sub
I did a bit of research and learned about SendKeys and using ExcelAPIs but I'm just taking baby steps here and not sure how these work or how to implement these ?.
Looking forward to all the help I can get. Thanks in advance.