使用VBA从WebPage下载文件 [英] Downloading File from WebPage using VBA
问题描述
您好。
如果这是一个简单的问题,我很抱歉,但我无法弄清楚如何从以下链接下载excel文件。 VBA代码必须选择"2011"的日期。 (框名='aaaaini')并按Excel图标下载文件并将其保存在确定的
目的地(例如桌面)中。该按钮基于Javascript。
由于
链接:spensiones.cl/apps/valoresCuotaFondo/vcfAFP.php?tf=A
您可能还需要隐藏保存/打开弹出窗口,请检查此链接 :
https://jwcooney.com/2014/03/31/remove-internet-explorer-open-or-save-popup/
呼叫刮(QUOT> /vcfAFP.php?tf=A")''在这里更改网站并执行此子。
结束子
Sub Scrape( url As String)
$
范围("a1:b100000").ClearContents
Dim x As long
Dim y As Long
 昏暗的浏览器作为InternetExplorer
  Dim Document As HTMLDocument
 昏暗的元素作为IHTMLElementCollection
 昏暗的元素作为IHTMLElement
 设置浏览器=新的InternetExplorer
  Browser.Visible = True
  Browser.navigate url
 做浏览器。浏览器而不浏览器.readyState = READYSTATE_COMPLETE
      DoEvents
 循环
 设置Document = Browser.Document
 暂停7''暂停7秒,以便javascript可以完成加载(一些慢速网站可能需要更多时间加载)
 设置Elements = Document.getElementsByTagName(" a")
 元素中的每个元素
 如果Element.Title =" Genera archivo en formato CSV con los valores correspondenceientes al rangodeañosseleccionado"然后
 元素。点击
 结束如果
 下一个
$
'Browser.Quit
结束子
''sub使暂停低于
公共子暂停(sngSecs为单身)
  Dim sngEnd As Single
  sngEnd = Timer + sngSecs
&NBSP;而Timer< sngEnd
&NBSP; &NBSP; &NBSP; DoEvents
&NBSP; Wend
b
结束分b
&NBSP;&NBSP;
Hello.
I'm sorry if this is an easy question but I can't figure out how to download the excel file from the link below. The VBA code must select the date to "2011" (box name = 'aaaaini') and press the Excel Icon to download and save the file in a determined destination (Desktop, for example). The button is based on Javascript.
Thanks.
Link: spensiones.cl/apps/valoresCuotaFondo/vcfAFP.php?tf=Ayou may also need to hide the save/open pop up window , check this link :
https://jwcooney.com/2014/03/31/remove-internet-explorer-open-or-save-popup/
Sub Playthissub()
Call Scrape("http://www.spensiones.cl/apps/valoresCuotaFondo/vcfAFP.php?tf=A") '' change the website here and execute this sub.
End Sub
Sub Scrape(url As String)
Range("a1:b100000").ClearContents
Dim x As Long
Dim y As Long
Dim Browser As InternetExplorer
Dim Document As HTMLDocument
Dim Elements As IHTMLElementCollection
Dim Element As IHTMLElement
Set Browser = New InternetExplorer
Browser.Visible = True
Browser.navigate url
Do While Browser.Busy And Not Browser.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Set Document = Browser.Document
Pause 7 '' pauses for 7 seconds so javascript can finish load ( some slow websites may need more time to load)
Set Elements = Document.getElementsByTagName("a")
For Each Element In Elements
If Element.Title = "Genera archivo en formato CSV con los valores correspondientes al rango de años seleccionado" Then
Element.Click
End If
Next
'Browser.Quit
End Sub
'' sub to make the pause below
Public Sub Pause(sngSecs As Single)
Dim sngEnd As Single
sngEnd = Timer + sngSecs
While Timer < sngEnd
DoEvents
Wend
End Sub
这篇关于使用VBA从WebPage下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!