我将从安全的网站下载文件。 每次保存时都会询问。
有什么方法可以从附件网页下载文件
建议我在没有提示的情况下将文件下载到特定路径
<a href="/ENIT/imsscsv_download.jsp?filename=07730_Dormant_Account_08022019.csv&filepath=/dmsapp/mnt/appln/DMSWeblogic/ENIT_FILES/COMMUNICATION_LOG/SENDER/INVESTIGATION_ALERTS/07730_Dormant_Account_08022019.csv">
07730_Dormant_Account_08022019.csv</a>
我也无法从上述网站链接下载文件
但是使用右键单击,系统直接允许文件保存
还有其他使用vba的选项来保存文件,而无需单击is href链接提示
请建议
答案 0 :(得分:0)
在下载文件时,最好使用XmlHttpRequest
而不是自动抓取网络。
使用以下宏:
Sub DownloadFile(ByVal fileLink As String, ByVal username, ByVal password)
Dim XmlHttpReq As Object
Set XmlHttpReq = CreateObject("Microsoft.XMLHTTP")
XmlHttpReq.Open "GET", fileLink, False, username, password
XmlHttpReq.send '<-- send the GET request of your resource file to the website
fileLink = XmlHttpReq.responseBody 'save response body
If XmlHttpReq.Status = 200 Then 'if GET request was OK
Set adodbStream = CreateObject("ADODB.Stream") 'Create a Stream
adodbStream.Open 'open it
adodbStream.Type = 1
adodbStream.Write XmlHttpReq.responseBody 'write response in it
adodbStream.SaveToFile "C:\file.csv", 2 ' 1 = doesn't overwrite, 2 = overwrites 'save it
adodbStream.Close 'close stream
End If
End Sub
...您应该能够像这样执行保存:
Sub YourMainMacro()
'... your code
DownloadFile yourAHRef, yourUsername, yourPassword
'...continue your code
End Sub