Consulting

Results 1 to 6 of 6

Thread: Need Help Fixing VBA Code for Comboboxes

  1. #1

    Need Help Fixing VBA Code for Comboboxes

    How do I modify the following code to always reference ComboBox1 on slide 4 for the Set oShape?

    I currently have to click the combobox and then run the macro. However when I send to another user the VBA is not active anymore unless I rerun the macro. I would like it to become static and fixed - "Only refering to Combobox1"


    Sub AddItemsToIncidentListBox()
    Dim oShape As Shape
    Set oShape = ActiveWindow.Selection.ShapeRange(1)
    With oShape.OLEFormat.Object
        ' Add items to the list
        .AddItem ("Earthquake")
        .AddItem ("Fire")
        .AddItem ("Medical")
        .AddItem ("Workplace Violence")
        .AddItem ("Bomb Scare")
        .AddItem ("Traffic Issue")
        .AddItem ("Building Incident")
        .AddItem ("Campus Incident")
        ' You could work with other properties of the list or combo box here as well
    End With
    End Sub


    KREEPA
    Last edited by Aussiebear; 04-28-2023 at 08:30 PM. Reason: Added code tags

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Assuming the activepresentation is your file.

    Set oShape = ActivePresentation.Slides(4).Shapes("Combobox1")
    Last edited by Aussiebear; 04-28-2023 at 08:30 PM. Reason: Adjusted the code tags
    Cheers
    Andy

  3. #3
    Any suggestions on how to make it automatically run once the workbook is open. Right now I have to do alt-f11 and run the macro for the list to appear in the dropdown. I would like to walk into a conference, open the file and have the dropdown be active immediately.

  4. #4
    Your mod works...thanks....I just want it to run behind the scenes without having to open up VBA and running a macro.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Try this

    Sub OnSlideShowPageChange()
    Dim s As Integer
    s = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
    If s <> 1 Then Exit Sub
    With ActivePresentation.Slides(4).Shapes("ComboBox1").OLEFormat.Object
        .Clear
        .AddItem "First"
        .AddItem "Second"
    End With
    End Sub
    Last edited by Aussiebear; 04-28-2023 at 08:31 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •