|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Function DownloadImage(url As String, filePath As String) As Boolean
- Dim httpReq As Object
- On Error GoTo ErrorHandler
- Set httpReq = CreateObject("MSXML2.XMLHTTP")
- With httpReq
- .Open "GET", url, False
- .Send
- End With
- If httpReq.Status = 200 Then
- With CreateObject("ADODB.Stream")
- .Open
- .Type = 1
- .Write httpReq.responseBody
- .SaveToFile filePath, 2
- .Close
- End With
- DownloadImage = True
- Else
- DownloadImage = False
- End If
- Exit Function
- ErrorHandler:
- DownloadImage = False
- End Function
复制代码 |
|