有这么个需求,Excel有一列是图片地址,现在需要将图片地址下载成图片。

那么如何处理呢?想来必然是要用VBA宏的。网上搜了下实现,demo代码如下:

Sub URLPictureInsert()
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set Rng = ActiveSheet.Range("A2:A5")
For Each cell In Rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
xCol = cell.Column + 1
Set xRg = Cells(cell.Row, xCol)
With Pshp
.LockAspectRatio = msoFalse
If .Width > xRg.Width Then .Width = xRg.Width * 2 / 3
If .Height > xRg.Height Then .Height = xRg.Height * 2 / 3
.Top = xRg.Top + (xRg.Height - .Height) / 2
.Left = xRg.Left + (xRg.Width - .Width) / 2
End With
lab:
Set Pshp = Nothing
Range("A2").Select
Next
Application.ScreenUpdating = True
End Sub

代码功能是将B2到B5的图片链接下载成图片放到A2到A5的单元格位置。

参考资料:
https://www.extendoffice.com/documents/excel/4212-excel-insert-image-from-url.html#a1



Related Posts: VBA如何将Excel中的图片地址下载成图片 :

留言