PDA

View Full Version : Run-time error '91' Click html button



emccracken
07-03-2018, 12:51 PM
I am working in VBA trying to go to a link, then click a button to export to .xls. I am getting a run-time error though. The debug takes me to this:

btnGo(0).Click
but here is my entire code: (I have extra variables because I copied and pasted from another previous code.)

Private Sub exportXLS()


Dim I As Long
Dim IE As Object
Dim doc As Object
Dim objElement As Object
Dim objCollection As Object
Dim btnGo As Object


' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True


' Send the form data To URL As POST binary request
IE.navigate "www.website.com"


' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set btnGo = IE.Document.GetElementsByTagName("Javascript:doClick(17)")
btnGo(0).Click

End Sub


html:

<a href="Javascript:doClick(17)" onmouseover="return(doOver(17,1));" onmouseout="return(doOver(17,0));"><img name="save_xls" alt="Export XLS" title="Export XLS" width="24" height="24" border="0" src="http://dsmdc-cog-web1.mediacomcorp.com/cognos/ppwb/Icon24/save_xls.gif"></a>

html for button image:

<img name="save_xls" alt="Export XLS" title="Export XLS" width="24" height="24" border="0" src="http://dsmdc-cog-web1.mediacomcorp.com/cognos/ppwb/Icon24/save_xls.gif">

mancubus
07-04-2018, 01:04 AM
btnGo vs btnGo(0)

why?

emccracken
07-04-2018, 03:26 PM
btnGo vs btnGo(0)

why?

That’s just the syntax I found online. I’m only self taught. If I change that will it work?

mancubus
07-04-2018, 11:55 PM
not guaranteed. :yes

just try it.

you'd better search it with "excel vba click a button on webpage" or similar keywords

emccracken
07-05-2018, 06:07 AM
not guaranteed. :yes

just try it.

you'd better search it with "excel vba click a button on webpage" or similar keywords

I did dozens of searches, some used variables, some didn't. I'm just not familiar with the syntax for IE button clicks.

I ran it without, and I got "Run-time error '438'; Object doesn't support this property or method." The website I am accessing is a secure website, does that have anything to do with it?

If I run the code up until the
btnGo.Click line, I can see the value assigned to the variable is "[object]". Is this what it should be?

emccracken
07-05-2018, 12:23 PM
The more that I look at the HTML, I'm focusing on the javascript part. Is that going to affect anything? I'm running a simple scrape VBA to return values, but for some reason it won't return values of the "a" tag, its only returning values if its in "frameset."

mancubus
07-05-2018, 11:34 PM
you should identify the button to be clicked

some ideas:
https://www.mrexcel.com/forum/excel-questions/709346-clicking-button-via-ie-automation-vba.html