【发布时间】:2013-09-20 20:22:21
【问题描述】:
我有一个简单的 VBA 代码(见下文),它转到网页,选择一些值,单击“开始下载”按钮,然后保存文件。问题是我被困在“点击下载按钮”部分。有人可以帮忙吗?
代码如下:
Sub Treasury_Auc_Notes()
Dim IE As Object
Set IE = Nothing
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://www.treasurydirect.gov/RI/OFAuctions?form=ndnld&typesec=notes"
While IE.Busy
DoEvents
Wend
IE.Document.All.Item("begYr").Value = "2012"
With IE.Document.getElementsByName("cols")
.Item(0).Checked = True
End With
'Click "Begin download" button (this is where I am stuck)
'Choose Save Open or Cancel (I haven’t got to this part yet)
ActiveWorkbook.SaveAs Filename
End Sub
【问题讨论】:
-
您需要创建另一个对象来表示按钮,可能使用
GetElementsByTagName方法,然后您可以调用该对象的.Click方法。