Vba_下载网络文件(图片)

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

你可能感兴趣的:(VBA)