Vba_Excel URLDownloadToFile 函數 ——下載網絡圖片到存放到本地磁盤
office 2010
/**
* imageURl 下載的圖片地址
* savePath 存儲的磁盤位置,絕對路徑
* DownloadWebImage 處理結果 true of false
**/
Public Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Integer, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Integer, ByVal lpfnCB As Integer) As Long '核心方法
Public Function DownloadWebImage(imageUrl As String, savePath As String) As Boolean '
On Error GoTo ErrL
Dim downl As Long
DeleteUrlCacheEntry (imageUrl) '清除緩存,防止出現重複資源
downl = URLDownloadToFile(0, imageUrl, savePath, 0, 0) '
DownloadWebImage = True
GoTo EndOk
ErrL:
Debug.Print "出現異常"
DownloadWebImage = False
EndOk:
End Function