有人知道如何使用Excel VBA获取此文件?
https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls
我使用了这段代码,但现在它不再起作用了:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
URLDownloadToFile 0, "https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls", "X:\TESORERIA\07 Prestamos\Préstamos 2016\financial_market_int_rates.xls", 0, 0
我也尝试过:
Sub download2()
Dim FileNum As Long
Dim FileData() As Byte
Dim WHTTP As Object
mainUrl = "https://www.centralbankmalta.org/"
fileUrl="https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls"
filePath = "X:\TESORERIA\07 Prestamos\Préstamos 2016\financial_market_int_rates.xls"
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
WHTTP.Open "POST", mainUrl, False
WHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WHTTP.Open "GET", fileUrl, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
FileNum = FreeFile
Open filePath For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
End Sub
此代码下载此信息而不是数字
所以我认为问题是ddos保护......或者可能是我已经将Office 2010更新到365了?
谢谢你的时间
1 回答
要么
将是最基本的方式 . 如果您需要它更漂亮,您可以使用Web浏览器控件并提供该URL . 这将触发它的行为与浏览器对待它的行为相同 .