Search code examples
vbapowerpointribbonx

Ribbon.InvalidateControl not working on PPT 2010


I have a an add-in within the Insert Ribbon of PPT 2010. Basically what I want to do is to make a selection in a combo box, then run a macro, then set the combo box to blank. Unfortunately I´v been unable to clear the selection.

I have searched all over the web with various methods and nothing helps. Hope someone can help.

My 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 code:

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

Solution

  • Alternatively use a Dropdown control instead of combobox

    I found some information here, at least enough to get started...

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

    Use XML like:

    <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>
    

    And VBA callbacks:

    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