Edgar Lopez
Edgar Lopez

Reputation: 1

Im unable to get click button on VBA script to work. Any advice?

Im automating a form with excel to autofill and submit. I am able to fill my form but I can't get the submit button to work. I've tried about 50 different types of code and I cant get it to work. Could you guys help me figure out how to get it to submit?

This is the HTML code for the button

field HTML properties Below

<input type="button" value="submit" class="button" onclick="submitIt()">

Here are 2 that I though would work but didnt

1st-- this one works but it gives me an error on the page which is weird. basically the error comes back as an incorrect company. but if i comment it out and fill the form and manually click the button it submits just fine.

IE.document.getElementsByClassName("button")(0).Click

2nd - I thought this worked at one point but i cant seem to get it to work now.

Set doc = IE.document
Set div = IE.document.getElementByClassnName("button")
div.FireEvent "submitIt"

Upvotes: 0

Views: 173

Answers (1)

ashleedawg
ashleedawg

Reputation: 21657

Welcome to Stack Overflow! This is a pretty common question.

Try:

<input type="submit" name="submit" value="mybutton">

and then

With IE.document

    Set elems = .getElementsByTagName("input")
    For Each e In elems

        If (e.getAttribute("value") = "mybutton") Then
            e.Click
            Exit For
        End If

    Next e

End With

More examples here, here, here, etc...

Here are some helpful tips to consider when posting questions.

Upvotes: 1

Related Questions