|
各位老师, 如何将下面的代码改为: 插入的图片高度等于单元格的高度, 图片宽度按比例缩放, 先谢过老师了!
Sub insertPic()
Dim rng As Range, FilPath$, ML, MT, MW, MH, shp As Shape, Myr&, i%
On Error Resume Next
Sheet1.Activate
For Each shp In ActiveSheet.Shapes
If shp.Type = msoAutoShape Then
shp.Delete
End If
Next
With Sheet1
For i = 2 To .Range("a65536").End(xlUp).Row
FilPath = ThisWorkbook.Path & "\图片\" & Cells(i, 2).Value & ".jpg" 'ThisWorkbook.Path
If Dir(FilPath) <> "" Then
Set rng = .Cells(i, 3)
With rng
ML = .Left + 1
MT = .Top + 1
MW = .Width - 1
MH = .Height - 1
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture FilPath
Selection.ShapeRange.Line.Visible = msoFalse
Selection.Placement = xlMoveAndSize
End With
End If
Next
.Cells(1, 1).Select
End With
If Err.Number <> 0 Then Err.Clear: On Error GoTo 0
End Sub
|
|