我想从网址下载Excel文件。
不幸的是,我只有包含“下载按钮”的网址,因为一旦我点击按钮,网址就不是... / file.xls而是一个,如果我去,则不会激活下载过程
VBA是否有办法转到此网址,然后点击按钮下载该文件。
Dim IE As InternetExplorer
Sub Test()
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.navigate "http://webpage.com/"
' Wait while IE loading...
While IE.Busy
DoEvents
Wend
Set objInputs = IE.Document.getElementsByTagName("link")
For Each ele In objInputs
If ele.Title Like "List of control sheets having one or more declared Then alert(s)." Then 'Text on the link
ele.Click
End If
Next
End Sub
但是,我认为我所针对的对象更像是一个链接而不是一个按钮,因为在源代码中,只有几行:
<LINK rel=stylesheet type=text/css href="/frm/wdk/theme/documentum/css/webforms.css">
答案 0 :(得分:1)
您可以使用它来使用IE访问页面:
Dim ie As Object
Set ie = CreateObject("InternetExplorer.application")
With ie
.Visible = True
.Navigate ("http://yourlink")
While .Busy Or .ReadyState <> 4: DoEvents: Wend
End With
然后使用命令SendKeys "{TAB}", True
转到按钮,并使用命令SendKeys "{ENTER}", True
点击它