Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Manipulating Listbox and Combobox controls on slides and forms

You can manipulate List and combo boxes on slides using the same properties as you can use to work with list and combo boxes on user forms, but when writing code, PowerPoint's intellisense feature doesn't help when you're working with such objects on a slide.

To work with them, you need to get a reference to the shape's OLEFormat.Object and manipulate it. The following example shows how:

Sub AddItemsToSelectedListBox()

Dim oShape As Shape
Set oShape = ActiveWindow.Selection.ShapeRange(1)

With oShape.OLEFormat.Object
    ' Add items to the list
    .AddItem ("This")
    .AddItem ("That")
    .AddItem ("The Other")
     ' You could work with other properties of the list or combo box here as well
End With

End Sub

Here's another example. Run InitListBox once to add a number for each slide in the presentation to ComboBox1.
When you choose any number from the combobox during a slide presentation, Sub ComboBox1_Change will send you to that numbered slide in the presentation

Private Sub ComboBox1_Change()
    On Error Resume Next
    SlideShowWindows(1).View.GotoSlide (CLng(ComboBox1))
End Sub

Sub InitListBox()

    Dim oShape As Shape
    Dim X As Long
    Set oShape = ActiveWindow.Selection.ShapeRange(1)

    With oShape.OLEFormat.Object
        ' Delete any existing items
        .Clear
        ' Add items to the list - one for each slide
        For X = 1 To ActivePresentation.Slides.Count
            .AddItem (CStr(X))
        Next
        ' You could work with other properties of the list or combo box here as well
    End With

End Sub

And another example that demonstrates how to load a combo box from an array. This one works with a combobox on a user form.

The form should contain a combobox named cboPicklist and a label named Label1.

Private Sub UserForm_Initialize()
' We'll load the combobox in the userform's Initialize event

    Dim i As Long
    Dim MyArray(6, 3)

     'Set the combo for 3 data columns, set their widths
    With Me.cboPicklist
        .ColumnCount = 3
        .Columnwidths = "12;36;36"
    End With

    'Load integer values into first column of MyArray
    For i = 0 To 5
        MyArray(i, 0) = i
    Next i

    'Load columns 2 and three of MyArray; pardon my French
    MyArray(0, 1) = "Zero"
    MyArray(1, 1) = "One"
    MyArray(2, 1) = "Two"
    MyArray(3, 1) = "Three"
    MyArray(4, 1) = "Four"
    MyArray(5, 1) = "Five"

    MyArray(0, 2) = "Zero"
    MyArray(1, 2) = "Un ou Une"
    MyArray(2, 2) = "Deux"
    MyArray(3, 2) = "Trois"
    MyArray(4, 2) = "Quatre"
    MyArray(5, 2) = "Cinq"

    ' Load the combo box by assigning the array to it
    Me.cboPicklist.List() = MyArray

    ' set the selection to the first item on the list
    ' (list is zero-based)
    Me.cboPicklist.ListIndex = 0

End Sub

Private Sub cboPicklist_Change()
' Whenever you pick something in the combobox, it will display here
    Me.Label1.Caption = Me.cboPicklist.Text
End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Manipulating Listbox and Combobox controls on slides and forms
http://www.pptfaq.com/FAQ00439_Manipulating_Listbox_and_Combobox_controls_on_slides_and_forms.htm
Last update 07 June, 2011
Created: