简体   繁体   English

在 PowerPoint 中使用 VBA 删除一张幻灯片上的所有图像

[英]Delete all Images on one Slide with VBA in PowerPoint

I want to delete only images on a slide with VBA in PowerPoint.我只想在 PowerPoint 中使用 VBA 删除幻灯片上的图像。

With the given code all shapes on the slide are being deleted.使用给定的代码,幻灯片上的所有形状都将被删除。

Sub DeleteAllPictures()

ActivePresentation.Slides(1).Shapes.Range.Delete

End Sub

The Images are added with the following Code:使用以下代码添加图像:

    Sub InsertPic_EAP()
  'Insert Picture
 ActivePresentation.Slides(1).Shapes.AddPicture FileName:="U:\Automatisierung\3D_Module\EAP.png", _
   LinkToFile:=msoTrue, _
   SaveWithDocument:=msoTrue, Left:=260, Top:=110, _
   Width:=270, Height:=250

 ActivePresentation.Slides(1).Shapes.AddPicture FileName:="U:\Automatisierung\Bilder_AP\EAP_01.png", _
   LinkToFile:=msoTrue, _
   SaveWithDocument:=msoTrue, Left:=620, Top:=220, _
   Width:=270, Height:=115

    End Sub

How do I modify the code to only select and delete the Images on the slide.如何修改代码以仅选择和删除幻灯片上的图像。

This code will work for you: Edit - For Linked Pictures此代码适用于您:编辑 - 对于链接的图片

Sub DeleteAllPictures()

Dim shp As Shape

    For Each shp In ActivePresentation.Slides(1).Shapes

    If shp.Type = msoLinkedPicture Then
        shp.Delete
    End If

    Next

End Sub

Looping through all the shapes in the slide and deleting if it is a picture.循环浏览幻灯片中的所有形状,如果是图片则删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM