PowerPoint VBA macro to dynamically change an image control in a slide show using a combo box control

Posted on 2005-04-05
Last Modified: 2012-06-27
¿How to?
In MS PowerPoint 2003 I would like to insert a combo box control and an image control into a slide.
The combo box will already have been populated with picture file names.
While in a powerpoint show, I would like a macro to insert/display the picture that the user selects from the combo box.
¿I would imagine that this is fairly straightforward?
I would need to somehow have Image1.picture = ComboBox1.value but I encounter mucho resistance....
Question by:canesbr
    LVL 76

    Accepted Solution

    Hi Brian,

    I thought this would be fairly simple but it proved to be a question that cost me a few gray hairs.  I sometimes cannot believe how difficult Microsoft makes doing what should be simple things.  Of course that's just my opinion.  I created the macro which is extremely simple, but then could not get it to work.  The pictures simply would not change.  It initially appeared as if the combobox's click event just wasn't working at all.  First, I added a msgbox popup that would be triggered when the Change event fired.  On running the show the msgbox did popup and the image changed.  I commented the msgbox out and the image again refused to change.  So, I added a textbox to display the name of the image currently being shown.  This forced me to resize the image control, pushing it down the screen some from its initial position.  I ran the show and flipped through the images.  Everything worked and the textbox showed the correct image name.  Then I took the msgbox out.  Again the image refused to change.  I put the msgbox back in and that's when I noticed what was happening.  Because the image was pushed further down the page the msgbox didn't completely cover it.  Instead, it only covered a small portion of the top.  But that part of the image changed.  That clued me in to what was happening.  The image was changing but the screen wasn't being redrawn.  I searched through the methods available and cannot find one that forces PowerPoint to redraw the image or the screen.  To get around this I simply turned the image's visibility property off and back on, thereby forcing the image to be redrawn.  It now works fine.  Here's the solution.  This code assumes that the combobox is named Combobox1 and the image is called Image1.  Adjust the names as needed.

    Private Sub ComboBox1_Change()
        Set Image1.Picture = LoadPicture(ComboBox1.List(ComboBox1.ListIndex))
        Image1.Visible = False
        Image1.Visible = True
    End Sub


    Author Comment

    Hi David,

    Great! - also gratifying that I wasn't imagining the difficulty.
    You heard of 'resistentialism'?
    Solution is great - except I had to use ComboBox1.Value - maybe I have a different version of the ComboBox control.
    Whatever works.

    Thank you,

    Author Comment


    Oh, and I have tried to stop using the term 'simple'.

                  Nothing is simpre.
    Stlaightfolwald, mayhaps, but simpre?
                Simpry not the case.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now