【发布时间】:2019-02-26 05:29:34
【问题描述】:
我正在使用 Microsoft Excel 2010 VBA,我正在尝试自动下载 pdf 报告。我可以导航到我需要去的地方,但我被困在最后一步;
有一个“导出”元素,其行为类似于链接。如果我单击它,它将启动 pdf 下载。我想自动执行此操作并将下载定向到指定文件夹,但是当我检查元素时,它似乎没有我可以调用它的元素 ID(即 getElementById().Click)。
我是 VBA IE 自动化的新手。有人对如何启动“导出”功能有建议吗?
我无法分享完整的 HTML 详细信息,因为它适用于包含敏感数据的网站,但以下是 HTML 的 sn-ps、我的 VBA 代码和有问题的 HTML 部分的屏幕截图:
<DIV style="FONT-SIZE: 8pt; HEIGHT: 30px; FONT-FAMILY: Verdana; DISPLAY: inline"><TABLE style="DISPLAY: inline" cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD height=28><SELECT id=PrintFormat><OPTION value="">Select a format</OPTION><OPTION selected value=Pdf>Acrobat (PDF) file</OPTION></SELECT></TD>
<TD width=4></TD>
<TD height=28><A onclick="if (document.getElementById('PrintFormat').value != '') {var url = document.getElementById('PrintFormat').value + 'Stream.aspx'; document.location.href = url;}" style="FONT-SIZE: 8pt; TEXT-DECORATION: none; FONT-FAMILY: Verdana" href="#" shape="">Export</A></TD></TR></TBODY></TABLE></DIV>
我的 vba 代码;
Sub pdfdownloadautomation()
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate Sheet3.Range("A1").Value 'A1 contains url
objIE.document.getElementById("PrintFormat").Value = "Pdf"
'works fine to this point - just not sure how to call the export
objIE.document.getElementById("?").Click
End Sub
【问题讨论】:
标签: vba internet-explorer web-scraping automation excel-2010