【问题标题】:Run a macro when I click a powerpoint shape in edit mode在编辑模式下单击 powerpoint 形状时运行宏
【发布时间】:2014-04-16 16:35:10
【问题描述】:

我希望能够在单击某个形状时更改它的某些值。但我想在 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() 方法。我想做同样的事情,但在编辑模式下,所以当演示文稿没有运行时。这可能吗?

【问题讨论】:

    标签: vba powerpoint mouseclick-event


    【解决方案1】:

    这是可能的,我只是自己做的,你只需要下载这个文件 http://www.officeoneonline.com/eventgen/EventGen20.zip 安装它 创建一个类模块 粘贴此代码 显式选项

    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
    

    结束子

    插入一个新模块 粘贴此代码

    将 cPPTObject 调暗为新的 Class1

    将 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
    

    现在运行 TrapEvents,只要您单击带有该文本的形状,您的子程序就会运行 感谢写这篇文章的人http://www.officeoneonline.com/eventgen/eventgen.html

    【讨论】:

      【解决方案2】:

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

      发布的代码没有多大意义。也许重新开始,然后说 what 当形状被点击时(在显示模式下)你想要发生的事情

      【讨论】:

      • 嗨,约翰。发布的代码似乎设置了形状,以便在单击时运行在变量 Subname 中找到的子例程。
      猜你喜欢
      • 2012-11-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      相关资源
      最近更新 更多