【问题标题】:Get name of control that calls macro in Powerpoint获取在 Powerpoint 中调用宏的控件的名称
【发布时间】:2012-08-08 07:07:08
【问题描述】:

在 VBA for PowerPoint 或 C# COM AddIn 中是否有办法识别调用宏的控件或处于活动状态的控件(确定它刚刚被单击)?

我知道

Globals.ThisAddIn.Application.ActiveWindow.Selection

,但是当您处于演示模式并且我在

下找不到任何内容时,这不起作用
Globals.ThisAddIn.Application.ActivePresentation

编辑: 我需要获取控件或其名称,以便可以将同一个 Sub 用于多个控件。

例子:

Public Sub RespondToControl(Control sender) 
    Dim AddIn As COMAddIn 
    Dim automationObject As Object 
    Set AddIn = Application.COMAddIns("MyAddIn") 
    Set automationObject = AddIn.object 
    Call automationObject.DoSomethingBasedOnNameOfControl(sender.Name) 
End Sub

【问题讨论】:

    标签: c# vsto powerpoint add-in


    【解决方案1】:

    如果您指的是开发人员工具箱中的控件(命令按钮、复选框等),则每个单独控件的 Click 事件中的代码将在幻灯片放映期间单击控件时运行。

    Private Sub CheckBox1_Click()
    MsgBox "You clicked CheckBox1"
    End Sub
    
    Private Sub CommandButton1_Click()
    MsgBox "You clicked CommandButton1"
    End Sub
    

    您是指其他类型的控件吗?

    你究竟需要完成什么?

    【讨论】:

    • 感谢您的回复,我直到现在才看到。不幸的是,它并没有解决我的问题,因为您没有识别调用控件,您只需调用特定于控件的代码。我需要获取控件或其名称,以便可以将同一个 Sub 用于多个控件。示例: Public Sub RespondToControl(Control sender) Dim AddIn As COMAddIn Dim automationObject As Object Set AddIn = Application.COMAddIns("MyAddIn") Set automationObject = AddIn.object 调用automationObject.DoSomethingBasedOnNameOfControl(sender.Name) End Sub
    • 抱歉上面的格式很糟糕,这是我在这里的第一条评论和换行符的降价(最后两个空格),似乎对我不起作用?
    猜你喜欢
    • 2012-11-09
    • 2012-02-17
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多