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?

2
  • 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. Commented Mar 2, 2016 at 6: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). Commented Mar 2, 2016 at 6:23

1 Answer 1

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')")
Sign up to request clarification or add additional context in comments.

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.