Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 转到url并单击按钮下载文件_Excel_Vba_Internet Explorer_Automation - Fatal编程技术网

Excel 转到url并单击按钮下载文件

Excel 转到url并单击按钮下载文件,excel,vba,internet-explorer,automation,Excel,Vba,Internet Explorer,Automation,我想从url下载Excel文件 不幸的是,我只有包含“下载按钮”的url,因为一旦我单击该按钮,url就不是…/file.xls,但如果我转到,其中一个将不会激活下载过程 有没有办法用VBA转到这个url并点击按钮下载文件 Dim IE As InternetExplorer Sub Test() ' Create InternetExplorer Object Set IE = CreateObject("InternetExplorer.Application") ' You can un

我想从url下载Excel文件

不幸的是,我只有包含“下载按钮”的url,因为一旦我单击该按钮,url就不是…/file.xls,但如果我转到,其中一个将不会激活下载过程

有没有办法用VBA转到这个url并点击按钮下载文件

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">

您可以使用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
Dim ie作为对象
设置ie=CreateObject(“InternetExplorer.application”)
与ie
.Visible=True
.导航(“http://yourlink") 
忙时或准备时状态4:DoEvents:Wend
以

然后使用命令
SendKeys“{TAB}”,True
转到按钮,使用命令
SendKeys“{ENTER}”,True
单击按钮

感谢您的回答。我应该如何确切地使用SendKeys“{TAB}”,对吗?我的意思是如何让VBA知道我说的是哪个按钮?实际上,在这种情况下,您需要手动计算实现按钮焦点所需的选项卡数,您也可以使用此命令ie.Document.All(“buttonnid”)。单击,但您必须知道在HTML源代码上看到的按钮ID值。这真的很酷。例如,如果按钮中心的位置是3(从左到右)和5(从下到上),我应该如何编写这行代码?如果使用ie.Document.All(“ButtonID”)。单击命令我认为更容易,例如源代码:您的代码将类似于ie.Document.All(“btnSearch”).点击我对你的方法做了很多研究,并在上面发布了我的代码。你能看一下吗?当做