|
本帖最后由 2338171 于 2023-4-14 09:10 编辑
Sub addpicture()
Set fso = CreateObject("Scripting.FileSystemObject")
Application.ScreenUpdating = False
For Each shp In ActiveSheet.Shapes
If shp.Type = 13 Then shp.Delete
Next shp
For j = 3 To 13 Step 5
For i = 2 To Cells(Rows.Count, 1).End(3).Row Step 11
Cells(i, j).Select
Set rng = Selection
str1 = ThisWorkbook.Path & "\插入图片" & Cells(i, j - 1) & ".jpg"
If fso.FileExists(str1) Then
ActiveSheet.Pictures.Insert(str1).Select
With Selection
.ShapeRange.LockAspectRatio = msoFalse
.Left = rng.Left + 1
.Top = rng.Top + 1
.Width = rng.Offset(0, 1).Left - rng.Left - 2
w = rng.Offset(1, 0).Top
y = rng.Top
.Height = w - y - 2
End With
End If
Next i
Next j
Application.ScreenUpdating = True
End Sub
|
|