使用宏使对象删除自身

时间:2019-01-24 03:23:53

标签: vba powerpoint powerpoint-vba

我有创建三个相同对象的代码,并为它们提供了单击时运行的宏。我需要这样做,以便他们在单击时也可以删除自己(或将自己移出屏幕)!

我已经尝试在ppMouseClick语句中添加.delete

Public Sub PopUpBattleTimes3()
BattleCounter = 0
SlideShowWindows(1).View.GotoSlide (7)

Dim oShp1 As Shape
Dim oShp2 As Shape
Dim oShp3 As Shape


Dim valuex As Integer
Dim valuey As Integer

valuex = CInt(Int((800 * rnd()) + 10))
valuey = CInt(Int((500 * rnd()) + 10))
Set oShp1 = ActivePresentation.Slides(7).Shapes.AddShape(msoShapeActionButtonCustom, valuex, valuey, 80, 50)
oShp1.TextFrame.TextRange.Text = "Object 1"
With oShp1.ActionSettings(ppMouseClick)
    .Action = ppActionRunMacro
    .Run = "AddToCounter"
End With


valuex = CInt(Int((800 * rnd()) + 10))
valuey = CInt(Int((500 * rnd()) + 10))
Set oShp2 = ActivePresentation.Slides(7).Shapes.AddShape(msoShapeActionButtonCustom, valuex, valuey, 80, 50)
oShp2.TextFrame.TextRange.Text = "Object2"
With oShp2.ActionSettings(ppMouseClick)
    .Action = ppActionRunMacro
    .Run = "AddToCounter"
End With

valuex = CInt(Int((800 * rnd()) + 10))
valuey = CInt(Int((500 * rnd()) + 10))
Set oShp3 = ActivePresentation.Slides(7).Shapes.AddShape(msoShapeActionButtonCustom, valuex, valuey, 80, 50)
oShp3.TextFrame.TextRange.Text = "Object3"
With oShp1.ActionSettings(ppMouseClick)
    .Action = ppActionRunMacro
    .Run = "AddToCounter"
End With
End Sub

如果有一些代码可以放入“ AddToCounter”宏或该宏内,可以帮助删除(或移出屏幕)被单击的对象,我真的很喜欢。谢谢你们的帮助!

1 个答案:

答案 0 :(得分:0)

请添加:

Public Sub AddToCounter(sh As Shape)
    sh.Delete
End Sub

如果在“ PopUpBattleTimes3”中为按钮指定了非默认名称,例如G。 oShp1.name = "TEST1",则可以在“ AddToCounter”中使用Select Case sh.Name来处理每个按钮的不同操作。