0

I am trying to write a vba to fill out a form details from excel and click a submit button using . I am new to vba and have got everything figured out except how to click the submit button.

My code is

Dim a
Set a = doc.getElementsByClassName("button")(1)
a.Click

Do While ie.Busy
    Application.Wait DateAdd("s", 1, Now)
Loop

No error comes up but it doesn't seem to do anything. Normally when the submit button is clicked a message pops up on screen saying "details uploaded", the URL doesn't change.

Source code from site is

<a class="button" onclick="document.getElementById('CustomTableInbox').innerHTML='';JS_UpdateTrack();" href="javascript:;">Submit</a>

Any help would be great!

5
  • Have you tried a simply ie.document.getElementsByTagName("form")(0).Submit ? Or, ie.document.querySelector(".buttons-div a").Click ? Commented Oct 25, 2018 at 14:05
  • ie.document.getElementsByClassName("buttons-div")(0).getElementsByTagName("a")(0).FireEvent "onclick" Commented Oct 25, 2018 at 14:11
  • Any of those work? Commented Oct 25, 2018 at 15:03
  • That first one you suggested worked perfectly, thanks so much! Don't seem to be able to accept it as an answer though.. sorry Commented Oct 26, 2018 at 20:43
  • I have added as an answer you can click. You can’t do that in comments. Sorry. Commented Oct 26, 2018 at 20:56

2 Answers 2

1

Try

Ie.document.getElementsByTagName("form")(0).submit

This gets the form by index and tag and then uses the submit method.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to refer an example below may help you to solve your issue.

HTML code:

<html>
<head>
</head>
<body>
<h2>Sample Page</h2>
<a href="http:\\Microsoft.com">Submit</a>
</body>
</html>

VBA Code:

Sub demo()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim Link As Object
Dim ElementCol As Object

Application.ScreenUpdating = False

Set ie = New InternetExplorer
ie.Visible = True

ie.navigate "C:\Users\Administrator\Desktop\demo57.html" 'Change the URL  as your requirement...

Do While ie.readyState <> READYSTATE_COMPLETE

DoEvents
Loop

Set html = ie.Document
Set ElementCol = html.getElementsByTagName("a")

For Each Link In ElementCol

If Link.innerHTML = "Submit" Then
Link.Click

End If
Next Link

Set ie = Nothing

Application.ScreenUpdating = True
End Sub

Output:

enter image description here

Further, You can try to modify the code as per your requirement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.