【发布时间】:2019-09-27 12:12:10
【问题描述】:
我有以下代码可以从网上下载文件,但我必须手动执行Save As。
Dim Filename As String
Dim ieApp As Object
Dim URL As String
URL = Range("All_Quad_URL")
Filename = "C:\Historic_Weather_Data\Precipitation\" & Range("File_Name").Value
Set ieApp = CreateObject("InternetExplorer.Application")
ieApp.Visible = True
ieApp.Navigate URL
While ieApp.Busy Or ieApp.ReadyState <> 45
DoEvents
Wend
ieApp.Quit
Set ieApp = Nothing
我想自动化Save As。我试过以下没有运气:
Controlling IE11 "Do you want to Open/Save" dialogue window buttons in VBA
我仍然看到带有打开/保存选项的“查看下载 - Internet Explorer”对话框。我把FindWindowEX改成了h = FindWindowEx(h, 0, "View Downloads - Internet Explorer", vbNullString)
另存为的文件名和位置需要是
Filename = "C:\Historic_Weather_Data\Precipitation\" & Range("File_Name").Value
我也来了
运行时错误“-2147467259 (80004005)”:对象“IWebBrowser 2”的方法“忙碌”失败”
调试到While ieApp.Busy 行。
感谢任何帮助。
【问题讨论】:
-
网址是什么?
-
假设 URL 是可下载文件的直接链接,请尝试不使用 IE。使用答案中给出的 URLDownloadToFile API 函数:stackoverflow.com/a/23299764/1467082
-
谢谢GSerg!!!成功了!!!