Sub
网络图片下载测试()
Dim
fileLink
As
String
Dim
saveFilePath
As
String
Dim
http
As
Object
Dim
stream
As
Object
Dim
contentType
As
String
fileLink =
"https://img2.baidu.com/it/u=2430257832,456548366&fm=253&fmt=auto?w=800&h=1067"
saveFilePath =
"C:\image3.png"
Set
http = CreateObject(
"MSXML2.XMLHTTP"
)
http.Open
"GET"
, fileLink,
False
http.Send
If
http.Status = 200
Then
Set
stream = CreateObject(
"ADODB.Stream"
)
stream.Type = 1
stream.Open
stream.Write http.ResponseBody
stream.SaveToFile saveFilePath, 2
stream.Close
MsgBox
"文件下载成功!"
, vbInformation
Else
MsgBox
"下载失败,状态码:"
& http.Status, vbCritical
End
If
Exit
Sub
End
Sub