如何批量插入照片到EXCEL,并自动适应表格

2025年03月24日 02:00
有1个网友回答
网友(1):

假设要根据A列内容,在同行B列插入当前文件目录下的子目录\pic中的jpg图片.
例如A1单元格内容是 zipall 要在B1单元格插入一个zipall.jpg图片

按住alt依次按f11,i,m
粘贴代码后按f5即可

Sub test()
For r = 1 To Range("a65536").End(xlUp).Row
n = ThisWorkbook.Path & "\pic\" & Cells(r, 1).Value & ".jpg"
With Cells(r, 2)
If Dir(n) = "" Then
.Value = "无相应图片"
Else
ActiveSheet.Shapes.AddPicture(n, False, True, .Left, .Top, .Width, .Height).Placement = xlMoveAndSize
End If
End With
Next
MsgBox "搞定!请勿重复运行!"
End Sub