Sub 批量插入图片()
Dim wj As String
Dim rng As Range
Sheets("sheet1").Select '选中要插入图片的工作表
x = [a65536].End(xlUp).Row '取得最后一行的行号
For i = 2 To x
na = Cells(i, 1) '从第一列(即A列)得到照片名,并以此名查找图片
wj = "e:\pic" &
"\" & na & ".jpg" '图片文件存储的路径与格式(.jpg)
If Dir(wj) <> "" Then
Cells(i, 2).Select '图片需要插入到第二列(即B列)
ActiveSheet.Pictures.Insert(wj).Select
Set rng = Cells(i, 5) '根据单元格的大小调整图片
With Selection
.Top =
rng.Top + 1
.Left =
rng.Left + 1
.Width =
rng.Width - 1
.Height =
rng.Height - 1
End With
End If
Next
MsgBox "图片插入完毕"
End Sub