如何使用vba点击图片?这是一个下载链接。我想自动保存文件。 HTML代码:
谢谢
<a onclick="location.href='/api/download.aspx?'+pixel.utils.getQueryPath()" href="javascript:;">
<img src="/images/zip.png" border="0" alt="indir">
</a>
&#13;
答案 0 :(得分:0)
尝试使用“onclick”?例如:
For Each ee In ehtml.getElementsByTagName("img")
If Trim(LCase(ee.src)) = ""/images/zip.png"" Then
ee.FireEvent ("onclick")
'''believe got popup for download after click the image
'''use your code to download from the popup
Exit For
End If
Next ee
答案 1 :(得分:0)
这是我修改了一下的代码。我之所以选择“Doevents”和“sleep”,是因为要确保宏运行正常并提交数据,因为此处的连接速度有点慢。没有伤害添加这个。希望可以解决你的问题:)
Dim ee as variant, elt as variant, bool as boolean: bool= False
DoEvents: Sleep 1000
For Each ee In HTMLDoc.getElementsByTagName("a")
If ee.ID = "finansalGit" Then
ee.Click: DoEvents: Sleep 1000: Exit For
End If
Next
Set HTMLDoc = MyBrowser.document
DoEvents: Sleep 1000
For Each ee In HTMLDoc.getElementsByTagName("iframe")
If Trim(LCase(ee.ID)) Like "*" & Trim(LCase("externalSite")) & "*" Then
For Each elt In ee.contentWindow.document.getElementsByTagName("a")
elt.Click
'''''or you can used this
elt.FireEvent ("onclick")
'''use your code to download from the popup
bool = True
Exit For
Next elt
End If
If bool Then
Exit For
End If
Next ee