从自定义功能区按钮运行powerpoint子过程

时间:2015-11-22 06:39:08

标签: button powerpoint ribbon

我在ThisAddIn类中有一个过程(请参阅下面的第一个代码块),我试图从我使用功能区设计器设计的自定义功能区按钮的单击事件中运行(请参阅第二个代码)。我不断收到错误消息:'对非共享成员的引用需要一个对象引用。我需要做些什么来解决这个问题?谢谢!

第一块:

Public Class ThisAddIn

    Public Sub fill_textboxes(ByVal control As Office.IRibbonControl)
            Application.DisplayAlerts = False
                For i = 1 To Application.ActiveWindow.Selection.ShapeRange.Count
                Application.ActiveWindow.Selection.ShapeRange(i).TextFrame.TextRange.Text = "..."
                Next
            Application.DisplayAlerts = True
    End Sub

第二块:

Private Sub fill_text_boxes_button_Click(sender As Object, e As RibbonControlEventArgs) Handles fill_text_boxes_button.Click

    Call ThisAddIn.fill_textboxes(fill_text_boxes_button)
End Sub

1 个答案:

答案 0 :(得分:1)

您需要将IRibbonControl接口的实例传递给fill_textboxes子。使用sender参数代表触发事件的控件:

Private Sub fill_text_boxes_button_Click(sender As Object, e As RibbonControlEventArgs) Handles fill_text_boxes_button.Click

   Call ThisAddIn.fill_textboxes(sender)
End Sub