Existence of shapes in Powerpoint

前端 未结 2 1267
醉话见心
醉话见心 2021-01-24 11:04

I would like to build a condition on a command button on a Macro enabled powerpoint presentation. If the shape exists then I would like it deleted, otherwise the button should p

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 11:43

    Some of the other suggestions will work but in general, it's bad practice to rely on selection unless absolutely necessary. Instead, you could call a slightly different function:

    Function ShapeExists(ByVal oSl as Slide, ByVal ShapeName as String) as Boolean
       Dim oSh as Shape
       For Each oSh in oSl.Shapes
         If oSh.Name = ShapeName Then
            ShapeExists = True
            Exit Function
         End If
       Next ' Shape
       ' No shape here, so though it's not strictly necessary:
       ShapeExists = False
    End Function
    

    You could also modify this to return a reference to the shape if found or nothing if not.

    If you prefer not to use early Exit Functions, there are easy ways to write around that.

提交回复
热议问题