1

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?

TAKL
  • 339
  • 4
  • 11
  • 1
    Try `Doc.getElementById("button1").click "100", "2016-03-02"` What language were you using when it worked ? Also would be helpful to post a URL or the relevant HTML. – Tim Williams Mar 02 '16 at 06:08
  • I can't provide the real URL since it requires me to login to a site (it's for clicking a button that books a session. However, I just used the console in Chrome. Also, your suggestion doesn't work in VBA, it still thinks nothing should be placed after the `.Click` (that error about invalid property assignments). – TAKL Mar 02 '16 at 06:23

1 Answers1

1

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')")
Community
  • 1
  • 1
TAKL
  • 339
  • 4
  • 11