写一个VBA代码在N列插入图片图片的大小为20100图片的目录在E资料SZHR2000HIEP-H照片图片的名称在D列的单元格内。
Sub InsertImage() Dim folderPath As String Dim fileName As String Dim imageWidth As Double Dim imageHeight As Double Dim i As Long
folderPath = "E:\资料\SZH\R2000HIEP-H照片\" '图片所在目录
imageWidth = 20 '图片宽度
imageHeight = 100 '图片高度
For i = 2 To Range("D" & Rows.Count).End(xlUp).Row '从第2行开始循环到D列最后一个非空单元格所在行
fileName = Range("D" & i).Value '获取图片名称
If fileName <> "" Then '如果图片名称非空
Range("N" & i).Activate '选中N列当前行
With ActiveSheet.Pictures.Insert(folderPath & fileName) '插入图片
.Left = ActiveCell.Left '设置图片左侧位置与当前单元格相同
.Top = ActiveCell.Top '设置图片顶部位置与当前单元格相同
.Width = imageWidth '设置图片宽度
.Height = imageHeight '设置图片高度
End With
End If
Next i
End Sub
原文地址: https://www.cveoy.top/t/topic/bpQg 著作权归作者所有。请勿转载和采集!