Clicking Submit button on a web page with VBA

14,758

Solution 1

For starters .getelementbytagname does not exist so this:

.Document.getelementbytagname("Submit").Click   

would fail. The method is .getElementsByTagName. There is a "s" after element, indicating that a collection of elements is returned.

The HTML you show is of an input tag as mentioned in the other answer. Submitting the form is a good way to go, or you can target that input tag and by its type attribute, using a CSS selector, and go with:

.document.querySelector("input[type=submit]").Click

Solution 2

The tag name is <input not submit but an easier way to do this is the use the form.submit() method:

.document.forms(0).submit

If there is only one form on the page then this should do the trick, otherwise you will need to enumerate through the form objects and test each one to see which one you want to submit.

Share:
14,758
Akkitech
Author by

Akkitech

Updated on June 04, 2022

Comments

  • Akkitech
    Akkitech almost 2 years

    I'm using IE version 9 and trying to click "submit" button using VBA. I've tried many ways but getting no luck.

    Can anyone please help? below is the element code of button. Please note that "on click" doesn't have space in real codes.

    Button code :

    <input type = submit value = " Submit " on click= "return submitDWAC(this.form)">
    

    I've already tried below, but they are not working.

    .Document.getelementbytagname("Submit").Click   
    
    .Document.all("Submit").click
    
    Sendkey {ENTER}, TRUE 
    

    Please assist.....

  • Akkitech
    Akkitech over 8 years
    so I have two buttons. One is SUBMIT and other one is RESET I'm putting their codes. It would be great if you can take a look and advise. <input type = submit value = " Submit " onClick = "return submitDWAC(this.form)"> &nbsp;&nbsp;&nbsp;<input type="reset" value=" Reset ">
  • SierraOscar
    SierraOscar over 8 years
    I just did take a look and advise - forget about the button, target the form instead and invoke the .submit method which is much easier and faster.
  • SierraOscar
    SierraOscar over 8 years
    That makes no sense, I don't know what you are asking. Just replace what you have with the line that I have supplied in my answer.
  • Akkitech
    Akkitech over 8 years
    I'll give it a try with below code in the morning .document.forms(0).submit