Search code examples
vbadrop-down-menupowerpointoffice-2010

Dropdown list (combobox) disappears when saving PowerPoint 2010 document


I created a drop down list in Power Point 2010, which works very well before saving the document. I used the following code in VBA:

Sub AddItemsToSelectedListBox()

Dim oShape As Shape

Set oShape = ActiveWindow.Selection.ShapeRange(1)

With oShape.OLEFormat.Object

' Add items to the list

.AddItem ("Good")

.AddItem ("Better")

.AddItem ("Best")

' You could work with other properties of the list or combo box here as well

End With

End Sub

f5 + close.

By going to the view modus, the drop down list works well. But if I save my power point document (in a .pptm format) and reopen the presentation, the lists don't drop down any more. If I enter the VBA, the code looks like this:

Sub AddItemsToSelectedListBox()

Dim oShape As Shape

Set oShape = ActiveWindow.Selection.ShapeRange(1)

With oShape.OLEFormat.Object

' Add items to the list

.AddItem ("Good")

.AddItem ("Better")

.AddItem ("Best")

' You could work with other properties of the list or combo box here as well

End With

End Sub

Private Sub ComboBox1_Change()

End Sub

The ComboBox_Change() Part is new. (Why?) Does anyone know, how to generate a dropdown list that survives the saving-process? Thank you very much!!


Solution

  • The _Change subroutine would be added when you doubleclick the combo box to get into the VBE.

    If you load the combo box from a subroutine in a module, it doesn't seem to retain the values when you save and reopen.

    If you load the combo box from an event in the box itself, it seems to work as you'd expect.

    For example:

    Private Sub ComboBox1_GotFocus()
    
    Dim oShape As Shape
    
    Set oShape = ActivePresentation.Slides(1).Shapes("ComboBox1")
    
    With oShape.OLEFormat.Object
    .Clear
    
    ' Add items to the list
    
    .AddItem ("Good")
    
    .AddItem ("Better")
    
    .AddItem ("Best")
    
    ' You could work with other properties of the list or combo box here as well
    
    End With
    End Sub