封装函数:
Sub 插入产品形象(strRange As String, datebaseTu As String) Dim strJpg As String strJpg = datebaseTu '... .jpg If Dir(strJpg, vbDirectory) <> "" Then ActiveSheet.Pictures.Insert(strJpg).Select Dim cT As Single Dim cL As Single Dim cW As Single Dim cH As Single Dim w As Single Dim h As Single cW = Range(strRange).Width cH = Range(strRange).Height cT = Range(strRange).Top cL = Range(strRange).Left w = Selection.Width h = Selection.Height If w / cW > h / cH Then Selection.Left = cL + 5 Selection.Width = cW - 5 - 5 '单元格宽度单边-5 不变形 Selection.Top = cT + cH / 2 - Selection.Height / 2 '高度居中 Else Selection.Top = cT + 5 Selection.Height = cH - 5 - 5 '单元格高度单边-5 不变形 Selection.Left = cL + cW / 2 - Selection.Width / 2 '宽度居中 End If Selection.Placement = xlMoveAndSize Selection.PrintObject = msoTrue End If End Sub Sub 删除图片(列号 As Integer, 行号 As Integer) Dim shp As Shape, i As Integer Dim s As String With ActiveSheet For i = .Shapes.Count To 1 Step -1 On Error Resume Next Set shp = .Shapes(i) If shp.TopLeftCell.Column = 列号 And shp.TopLeftCell.Row = 行号 Then shp.Delete End If Next End With End Sub