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">
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">