Ribbon.InvalidateControl无法在PPT 2010上运行

时间:2014-07-23 00:17:20

标签: vba powerpoint powerpoint-vba ribbonx

我在PPT 2010的插入功能区中有一个加载项。基本上我想要做的是在组合框中进行选择,然后运行宏,然后将组合框设置为空白。不幸的是我无法清除选择。

我用各种方法在网上搜索,没有任何帮助。希望有人可以提供帮助。

我的XML

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="VirtusInitialize">
<ribbon>
<tabs>
<tab idMso="TabInsert">
<group id="CustomGroup1" label="Sticker">
<box id="box1" boxStyle="horizontal">
    <comboBox id="ddlItem" label="STICKER 1" onChange="Sticker1">
      <item id="BU" label="BACK UP" />
    </comboBox>
</box>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

VBA代码:

Private MyRibbonV As IRibbonUI


Public Sub VirtusInitialize(ByVal ribbon As Office.IRibbonUI)
  Set MyRibbonV = ribbon
End Sub

Sub Sticker1(ByVal control As IRibbonControl, text As String)
 'do stuff
  MyRibbonV.InvalidateControl ("ddlItem")
End Sub

2 个答案:

答案 0 :(得分:1)

或者使用Dropdown控件代替组合框

我在这里找到了一些信息,至少足以开始......

http://gregmaxey.mvps.org/word_tip_pages/customize_ribbon_main.html

使用XML,如:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="VirtusInitialize">
<ribbon>
<tabs>
<tab idMso="TabInsert">
<group id="CustomGroup1" label="Sticker">
<box id="box1" boxStyle="horizontal">
    <dropDown id="ddlItem" label="STICKER 1" 
                      getItemCount="GetItemCount"
                      getItemLabel="GetItemLabel"
                      getSelectedItemIndex="GetSelectedItemIndex"
                      onAction="Sticker1" >
    </dropDown>
</box>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

和VBA回调:

Private MyRibbonV As IRibbonUI

Public Sub VirtusInitialize(ByVal ribbon As Office.IRibbonUI)
  Set MyRibbonV = ribbon
End Sub

Sub Sticker1(ByVal control As IRibbonControl, id As String, index As Integer)
 'do stuff
  Select Case index
      Case 0

      Case 1
      'do stuff
      Case 2
      'do stuff
  End Select

  MyRibbonV.Invalidate
End Sub


'Callback for ddlItem getItemCount
Sub GetItemCount(control As IRibbonControl, ByRef returnedVal)
'puts 3 items in the dropdown and triggers the GetItemLabel
returnedVal = 3
End Sub

'Callback for ddlItem getItemLabel
Sub GetItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
Dim str$
Select Case index
    Case 0
        str = " "
    Case 1
        str = "BACK UP"
    Case 2
        str = "GO FORWARD"
End Select
returnedVal = str
End Sub

'Callback for ddlItem getSelectedItemIndex
Sub GetSelectedItemIndex(control As IRibbonControl, ByRef returnedVal)
'not used
End Sub
'Callback for ddlItem getText
Sub GetText(control As IRibbonControl, ByRef returnedVal)
'not used
End Sub
'Callback for ddlItem getItemID
Sub GetItemID(control As IRibbonControl, index As Integer, ByRef id)
'not used...
End Sub

答案 1 :(得分:0)

试试这个:

Sub Sticker1(ByVal control As IRibbonControl, text As String)
'do stuff
Call MyRibbonV.InvalidateControl ("ddlItem")
End Sub

请注意,关键字“Call”已添加到原始代码中。