Vba 在编辑模式下单击powerpoint形状时运行宏

Vba 在编辑模式下单击powerpoint形状时运行宏,vba,powerpoint,mouseclick-event,Vba,Powerpoint,Mouseclick Event,我希望在单击某个形状时能够更改该形状的某些值。但我想在powerpoint处于编辑模式时(我不知道是否是这样说的),而不是在幻灯片放映模式下。我一直在互联网上寻找,我只找到了一种方法,使它在幻灯片放映模式,所以当演示正在运行 这是我找到的代码 Private Sub createSwipeNext(color) Dim swipArrow As Shape Dim subName As String subName = "Identify" Set cSlide

我希望在单击某个形状时能够更改该形状的某些值。但我想在powerpoint处于编辑模式时(我不知道是否是这样说的),而不是在幻灯片放映模式下。我一直在互联网上寻找,我只找到了一种方法,使它在幻灯片放映模式,所以当演示正在运行

这是我找到的代码

Private Sub createSwipeNext(color)
    Dim swipArrow As Shape
    Dim subName As String
    subName = "Identify"
    Set cSlide = Application.ActiveWindow.View.Slide
    'ActiveWindow.Selection.Unselect
    Set swipArrow = cSlide.Shapes.AddShape(msoShapeRightArrow, ActivePresentation.SlideMaster.width + 10, ActivePresentation.SlideMaster.height / 2, 40, 30)
    If color = "green" Then
        swipArrow.Fill.ForeColor.RGB = vbGreen
    Else
        swipArrow.Fill.ForeColor.RGB = vbRed
    End If
    swipArrow.name = "Dink swipe arrow"

    'swipArrow.ActionSettings(ppMouseClick).Run = subName
    With swipArrow.ActionSettings(ppMouseClick) ' or ppMouseOver if you prefer
         .Run = subName
         .Action = ppActionRunMacro
      End With
 End Sub

使用此代码,可以在幻灯片放映模式下单击形状并运行Identify()方法。我想在编辑模式下进行相同的操作,以便在演示文稿未运行时。这可能吗?

可能,但绝对不容易。您需要编写一个类模块来检测选择事件


发布的代码没有多大意义。也许可以重新开始,只需说当形状被锁定时(在显示模式下)

你想发生什么可以这样做,我只是自己做了,现在你只需要下载这个文件 安装它 创建一个类模块 粘贴此代码 选项显式

Public WithEvents PPTEvent As Application



Private Sub Class_Initialize()
End Sub


Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
If Sel.Type = ppSelectionShapes Then
    If Sel.ShapeRange.HasTextFrame Then
        If Sel.ShapeRange.TextFrame.HasText Then
           If Trim(Sel.ShapeRange.TextFrame.TextRange.Text) = "Text inside your shape" Then
              Sel.Unselect
              yoursub
           End If
       End If
     End If

   End If
端接头

插入新模块 粘贴此代码

将对象设置为新类别1

Dim TrapFlag作为布尔值

 Sub TrapEvents()
      If TrapFlag = True Then
         MsgBox "Already Working"
         Exit Sub
      End If
    Set cPPTObject.PPTEvent = Application
    TrapFlag = True
 End Sub




 Sub ReleaseTrap()
      If TrapFlag = True Then
         Set cPPTObject.PPTEvent = Nothing
         Set cPPTObject = Nothing
         TrapFlag = False
      End If
 End Sub

 Sub yoursub()
         MsgBox "Your Sub is working"
 End Sub
现在运行TrapeEvents,当您单击其中包含该文本的形状时,您的sub将运行
感谢写这篇文章的人

Hiya John。发布的代码似乎设置了形状,以便在单击时运行变量Subname中的子例程。