[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2005-04-05
Medium Priority
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
  • 2
LVL 76

Accepted Solution

David Lee earned 2000 total points
ID: 13721832
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

ID: 13723543
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

ID: 13727431

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

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


Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

834 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