写一个VBA代码从D1单元格开始判断是否为空如果为空则跳过不为空则用E资料SZHR2000HIEP-H照片这个目录加上本单元格的内容组成路径将路径的图片插入当前行的N列的单元格内图片大小为20100居处居中
Sub InsertPicture() Dim i As Integer Dim filePath As String Dim cellValue As String Dim picWidth As Integer Dim picHeight As Integer
'设置图片大小
picWidth = 20
picHeight = 100
'从D1单元格开始循环判断
For i = 1 To Rows.Count
If Range("D" & i).Value = "" Then
'如果D单元格为空则跳过
Continue For
Else
'组合图片路径
cellValue = Range("D" & i).Value
filePath = "E:\资料\SZH\R2000HIEP-H照片\" & cellValue & ".jpg"
'在N单元格内插入图片
With Range("N" & i)
.Activate
.ClearContents
If Dir(filePath) <> "" Then
.Select
With .Parent.Pictures.Insert(filePath)
.Width = picWidth
.Height = picHeight
.Top = .Top + (.Height - picHeight) / 2
.Left = .Left + (.Width - picWidth) / 2
End With
Else
.Value = "图片不存在"
End If
End With
End If
Next i
End Sub
原文地址: http://www.cveoy.top/t/topic/bp2Z 著作权归作者所有。请勿转载和采集!