Sub Save_image()
Dim oHTTP As Object
Dim sDestFolder As String
Dim sSrcUrl As String
Dim sImageFile As String
sDestFolder = "C:\Users\adale\Desktop\Compendium Images\"
sSrcUrl = ActiveCell.Value
If Left(sSrcUrl, 2) = "//" Then
sSrcUrl = "http:" & sSrcUrl
End If
sImageFile = Right(ActiveCell.Value, Len(ActiveCell.Value) - InStrRev(ActiveCell.Value, "/"))
Debug.Print sImageFile
ActiveCell.Offset(0, 2).Value = sImageFile
Set oHTTP = CreateObject("msxml2.XMLHTTP")
oHTTP.Open "GET", sSrcUrl, False
oHTTP.send
Set oStream = CreateObject("ADODB.Stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
oStream.Type = adTypeBinary
oStream.Open
oStream.write oHTTP.responseBody
oStream.savetofile sDestFolder & sImageFile, adSaveCreateOverWrite
Set oStream = Nothing
Set oHTTP = Nothing
End Sub
从以下代码中获取:http://tipsformarketers.com/use-excel-to-download-hundreds-of-images-instantly/
我有一张包含3列的Excel工作表,其中包含图片的网址,请参阅附加的示例图片:
VBA例程可以处理每个列的运行,将图像下载到本地计算机(PC),同时还创建/维护目录结构,例如,创建本地嵌套文件夹:/wp-content/uploads/XXXX/XX/file_name.jpg。