VBA to Enter Data Online and Submit Form - vba

I'm trying to use VBA to submit data from Excel to a webform online. The issue happens within the * area where I'm trying to select and update the form. I've tried a variety of options (getelement by ID, name, etc.) without any success. I believe the issue has to do with identifying the appropriate element. I've seen advice about using the Locals feature in VBA, but I'm not sure how to use that for this purpose. I have a feeling someone with some experience could figure this out very quickly by looking at the source code on the webiste, using Locals in VBA, or some other technique.
The form is set up so all fields are text and I can enter/submit data online with no problem.
Thanks in advance for any help/suggestions.
Dim IE As Object
Sub submitFeedback3()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://spreadsheetbootcamp.com/excel-efficiency-trainer-feedback/"
Application.StatusBar = "Submitting"
' Wait while IE loading...
While IE.Busy
DoEvents
Wend
**********************************************************************
IE.Document.getElementById("Form_Attempts-1372643500")(0).Value = "1"
IE.Document.getElementById("submit-1-1372643500")(0).Click
**********************************************************************
Application.StatusBar = "Form Submitted"
IE.Quit
Set IE = Nothing
Application.ScreenUpdating = True
End Sub

Try below code
Dim IE As Object
Sub submitFeedback3()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://spreadsheetbootcamp.com/excel-efficiency-trainer-feedback/"
Application.StatusBar = "Submitting"
' Wait while IE loading...
While IE.Busy
DoEvents
Wend
' **********************************************************************
delay 5
IE.Document.getElementById("experience-1372700847").Value = "ddddd1"
delay 5
IE.Document.getElementById("Form_Time_Best-1372700847").Value = "ddddddddddd2"
delay 5
IE.Document.getElementById("submit-1-1372700847").Click
'**********************************************************************
Application.StatusBar = "Form Submitted"
IE.Quit
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
Private Sub delay(seconds As Long)
Dim endTime As Date
endTime = DateAdd("s", seconds, Now())
Do While Now() < endTime
DoEvents
Loop
End Sub

Related

How would you click an I'm Not a Robot checkbox with visual basic?

Is it possible to use visual basic to click an I'm Not A Robot checkbox using visual basic.
Here's the code I tried:
ie.Document.getElementById("recaptcha-checkbox-checkmark").Click
The above code was used after creating an ie Object as follows:
Sub DoBusinessSearch()
Dim strResults As String
Dim ofacname As String
ofacname = Excel.Range("Company").Value
Application.ScreenUpdating = True
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://mycpa.cpa.state.tx.us/coa/Index.html"
ie.Fullscreen = True
Application.StatusBar = "Submitting"
' Wait while IE loading...
While ie.Busy
DoEvents
Wend
' **********************************************************************
delay 1
ie.Document.getElementById("entityName").Value = ofacname
delay 1
ie.Document.getElementById("recaptcha-checkbox-checkmark").Click
delay 1
ie.Document.getElementById("search").Click
Application.SendKeys "(%{1068})"
'**********************************************************************

Not able to login to a webpage using excel, error 424 object required

I am trying to login to this webpage, https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp
using VBA. Debugging shows me that the VBA throws an error 424 object required when username line is active (apparently it is not able to fill the username data).
Here's the code:
Sub Test()
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.Navigate ("https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp")
With ie.document
.getElementById("txtUserId").Value = "ABCDE"
.getElementById("txtPassword").Value = "ABCDE"
.getElementById("submit").Click
End With
End Sub
Can anyone help me with debugging the problem while logging in to the given webpage?
Take a look at the below example:
Option Explicit
Sub Test()
Dim oIE As Object
Set oIE = CreateObject("InternetExplorer.application")
With oIE
.Visible = True
.Navigate ("https://www.fois.indianrail.gov.in/ecustomer/JSP/QryInsight.jsp")
Do While .ReadyState < 4 Or .Busy
DoEvents
Loop
With .Document
Do While .ReadyState <> "complete"
DoEvents
Loop
With .parentWindow.frames("frmCUMain").document
.getElementsByName("txtUserId")(0).Value = "ABCDE"
.getElementsByName("txtPassword")(0).Value = "ABCDE"
.getElementsByName("cmdLogin")(0).Click
End With
End With
End With
End Sub

I am getting an error " The object invoked has disconnected from its clients" when automating my website

Below is the code i am using
Sub IE_try()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "my site"
Application.StatusBar = "Submitting"
While IE.Busy
DoEvents
Wend
delay 5
IE.Document.getElementByClass("ms-textSmall ms-srch-sb-prompt ms-helperText").Value = "abc"
IE.Documnet.getElementByName("ms-srch-sb-searchImg").Click
End Sub
Error message:
Thanks in advance :)
You are getting a strange error. In general your code is a bit wrong - you should use getElementsByClassname and not getElementsByClass. Here is something to start with, working for the StackOverflow site, writing abv in the search engine.
Option Explicit
Sub IE_try()
Dim Element As Object
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://stackoverflow.com"
While IE.Busy
DoEvents
Wend
Set Element = IE.Document.getElementsByClassname("f-input js-search-field")
Element.Item.Value = "abv"
End Sub

Reference Cell in VBA Script

I was curious if there is a way to reference a specific cell within the following VBA script. The cell contains a date in yyyymmdd format, which would go in the commented section below.
Sub OpenData()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.navigate "http://website.com/'desired cell value'/subdirectory/file.txt"
'Check for good connection to web page loop!
Do
If IE.readyState = 4 Then
IE.Visible = True
Exit Do
Else
DoEvents
End If
Loop
'Wait for window to open!
Application.wait (Now + TimeValue("0:00:02"))
'MsgBox "Done"
IE.Visible = True
Eric
Have you tried format?
'...
IE.navigate "http://website.com/" & Format (Cells(1,1).Value, “dd/MM/yyyy”) & "/subdirectory/file.txt" '...

Press a link on a webpage using Excel VBA

I have this code where it goes to Minecraft.net and enters the username and password, and then goes to the profile page. I need to change the password on the account, which will be in cell A1 of the worksheet. I can't seem to figure out how to click the change password link. This is my code so far:
Dim IE As Object
Sub submitFeedback3()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://minecraft.net/login"
Application.StatusBar = "Submitting"
' Wait while IE loading...
While IE.Busy
DoEvents
Wend
' **********************************************************************
IE.Document.getElementById("username").Value = "dddddddd"
IE.Document.getElementById("password").Value = "ddd"
IE.Document.getElementById("signin").Click
'**********************************************************************
Application.StatusBar = "Form Submitted"
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
If the click doesn't work then you could try to submit the html form.
' Add reference to Microsoft Internet Controls
' Add reference to Microsoft HTML Object Library
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate "https://minecraft.net/login"
While IE.Busy
DoEvents
Wend
IE.Document.getElementById("username").Value = "dddddddd"
IE.Document.getElementById("password").Value = "ddd"
Dim htmlForm As HTMLFormElement
Set htmlForm = IE.Document.getElementById("loginForm")
htmlForm.submit