Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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 用VB实现IE的自动化;将目标另存为";_Excel_Internet Explorer_Save As - Fatal编程技术网

Excel 用VB实现IE的自动化;将目标另存为";

Excel 用VB实现IE的自动化;将目标另存为";,excel,internet-explorer,save-as,Excel,Internet Explorer,Save As,我正在尝试使用excel VB宏从受密码保护的会员网站下载excel文件。我正在使用“InternetExplorer”对象打开浏览器窗口,登录并浏览到正确的页面,然后扫描页面中我想要的链接。使用工作簿.Open(URLstring)不起作用,因为Excel未被记录。它打开html页面而不是实际文件,请求登录 我的首选是使用VB宏在internet explorer中的正确链接上自动执行右键单击“目标另存为”事件,但我不知道具体如何执行此操作。使用internet explorer API确实没

我正在尝试使用excel VB宏从受密码保护的会员网站下载excel文件。我正在使用“InternetExplorer”对象打开浏览器窗口,登录并浏览到正确的页面,然后扫描页面中我想要的链接。使用工作簿.Open(URLstring)不起作用,因为Excel未被记录。它打开html页面而不是实际文件,请求登录


我的首选是使用VB宏在internet explorer中的正确链接上自动执行右键单击“目标另存为”事件,但我不知道具体如何执行此操作。

使用internet explorer API确实没有办法做到这一点。如果它只是一个一次性脚本,您可能可以证明自己使用SendKeys是合理的

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
...
Sub YourMacro()
    ... Navigate IE to the correct document, and get it to pop 
    up the "Save As" dialog ...

    Set sh = CreateObject("WScript.Shell")
    sh.AppActivate "File Download"
    sh.SendKeys "S"
    Sleep 100
    sh.SendKeys "C:\Path\filename.ext{ENTER}"
End Sub

如果您知道要下载的文件的URL,可以使用以下例程:

Sub HTTPDownloadFile(ByVal URL As String, ByVal LocalFileName As String)
    Dim http As Object ' Inet
    Dim Contents() As Byte

    Set http = New Inet
    Set http = CreateObject("InetCtls.Inet")
    With http
        .protocol = icHTTP
        .URL = URL
        Contents() = .OpenURL(.URL, icByteArray)
    End With
    Set http = Nothing

    Open LocalFileName For Binary Access Write As #1
    Put #1, , Contents()
    Close #1
End Sub