TAKL
TAKL

Reputation: 339

VBA IE click button that requires argument?

I'm using Excel and programming in VBA.

I've located a button that I want to click. However, it seems this button requires an argument.

Using the Console in Chrome, I typed this:

document.getElementById("button1").click

That line resolved function click() { [native code] } so instead I tried this:

document.getElementById("button1").click ('100', '2016-03-02')

And it worked. So, how do I run the same thing from VBA?

I have tried the following:

Sub ClickTheButton()
Dim IE As SHDocVw.InternetExplorer
Dim Doc As MSHTML.HTMLDocument

Set IE = New SHDocVw.InternetExplorer

With IE
    .Visible = True
    .Navigate "(webpage here)"

    Do Until Not .Busy And .ReadyState = 4
        DoEvents
    Loop

    Set Doc = .Document

    Doc.GetElementByID("button1").Click ' nothing happens when running this
    Doc.GetElementByID("button1").Click "('100', '2016-03-02')" ' not working (can't even attempt to run this)
    Doc.GetElementByID("button1").Click ("'100', '2016-03-02'") ' not working (can't even attempt to run this)

End With
End Sub

I can't run the procedure, because of the code after .Click returning Wrong number of arguments or invalid property assignments.

Any ideas?

Upvotes: 1

Views: 638

Answers (1)

TAKL
TAKL

Reputation: 339

Answer found here.

The click button ran a function. Instead of clicking the button I could instead just run the function like this:

Dim CurrentWindow As HTMLWindowProxy    
Set CurrentWindow = IE.Document.parentWindow
Call CurrentWindow.execScript("xajax_DoCalReservation('100', '2016-03-02')")

Upvotes: 1

Related Questions