|
思路:插入图片的同时,在单元格内输入一个数,作记号;第二次运行代码,先检查,没有记号的,才运行插入图片代码。这样,就避免了重复插入。修改代码如下:
Sub test()
Dim r As Integer, i As Integer, iy As Integer
r = [c65536].End(xlUp).Row
For i = 4 To r Step 7
If Cells(i, 1) = "" Then
If Dir(ThisWorkbook.Path & "\" & Cells(i, 2) & ".jpg") <> "" Then
With ActiveSheet.Pictures.Insert(ThisWorkbook.Path & "\" & Cells(i, 2) & ".jpg").ShapeRange
.LockAspectRatio = msoFalse
.Left = Cells(i, 1).Left
.Top = Cells(i, 1).Top
.Height = Cells(i, 1).MergeArea.Height
.Width = Cells(i, 1).MergeArea.Width
End With
Cells(i, 1) = i
End If
End If
Next i
End Sub |
|