如何在粘贴新对象之前从 excel 中的 VBA 代码中删除 powerpoint 中的图片?

How to delete a picture in powerpoint from VBA code in excel before pasting new object?

对 VBA 很陌生。 这是我用来粘贴到空白 powerpoint 幻灯片(一直工作正常)的代码,但是当我需要为接下来的几个月更新数据时,我不确定如何在粘贴新图片之前删除旧图片... 任何帮助表示赞赏。

  Sheets("Presentation").Select
  Range("b53:w99").Select
  Selection.CopyPicture Format:=xlPicture
  With PptActvWin
    .View.GotoSlide Index:=3
    .View.PasteSpecial DataType:=ppPastePicture
    pptApp.ActiveWindow.Selection.ShapeRange.Left = 2.5 * 72 * 0.393700787
    pptApp.ActiveWindow.Selection.ShapeRange.Top = 2.5 * 72 * 0.393700787
    pptApp.ActiveWindow.Selection.ShapeRange.ScaleHeight 0.45, msoTrue, 
  msoScaleFromTopLeft
    pptApp.ActiveWindow.ViewType = ppViewNormal
  End With

在粘贴图片之前,循环浏览活动幻灯片中的所有形状并删除它们。

With PptActvWin
.View.GotoSlide Index:=3
For Each oSh In .View.Slide.Shapes
    If oSh.Type = msoPicture Then
        oSh.Delete
    End If
Next
.View.PasteSpecial DataType:=ppPastePicture
pptApp.ActiveWindow.Selection.ShapeRange.Left = 2.5 * 72 * 0.393700787
pptApp.ActiveWindow.Selection.ShapeRange.Top = 2.5 * 72 * 0.393700787
pptApp.ActiveWindow.Selection.ShapeRange.ScaleHeight 0.45, msoTrue, msoScaleFromTopLeft
pptApp.ActiveWindow.ViewType = ppViewNormal

结束于