logo
search
VBA & Macro Problems

How to Load an Image into an Excel Shape on ActiveX Combo Box Change via VBA

Maira MehtabMaira Mehtab Sep 27, 2026 869 views

Question details

The user needs to write a VBA macro that automatically loads a student's picture into a specific Excel shape named "PICS" whenever a new selection is made in an ActiveX combo box.

Product
Excel
Device & OS
not provided
Scenario
Creating a dynamic dashboard or student profile viewer where changing a dropdown selection automatically updates the corresponding profile picture inside a designated shape.
Observed behavior
The user is seeking the correct VBA methodology or code snippet to link an ActiveX combo box change event to a shape's image fill property.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled Developer tools in your spreadsheet application to access the Visual Basic Editor.

Solution 1Recommended

Use the VBA ComboBox Change Event

Utilize the Worksheet's code module to trigger an image update macro whenever the ActiveX combo box value changes.

To achieve this, you need to tie the shape's fill property to the specific ActiveX control event. When the user selects a new name from the combo box, the VBA script will construct the file path to the corresponding image and load it into the shape named 'PICS'.

1
Open the Visual Basic Editor

Press 'Alt + F11' to open the VBA Editor, then double-click the worksheet containing your ActiveX Combo Box in the Project Explorer.

2
Create the Change Event Subroutine

Select your ComboBox from the top-left object dropdown and choose the 'Change' event from the top-right procedure dropdown to generate a 'Private Sub ComboBox1_Change()' subroutine.

3
Define the Image Path

Inside the subroutine, declare a string variable and construct the image path based on the combo box value (e.g., ImagePath = "C:\StudentPhotos\" & ComboBox1.Value & ".jpg").

4
Update the Shape's Picture

Use the code 'Me.Shapes("PICS").Fill.UserPicture ImagePath' to dynamically load the new image into your designated shape.

Need Further VBA Help?: For complex VBA troubleshooting or if you encounter errors, it is highly recommended to post your specific code and workbook structure on Stack Overflow using the 'vba' tag. Include a clear title and enough information to reproduce the issue.
Advanced Macro Support in WPS

Execute VBA Macros Seamlessly with WPS Spreadsheet

WPS Spreadsheet offers robust compatibility with Excel VBA macros, allowing you to run complex scripts, utilize ActiveX controls, and manipulate dynamic shape properties efficiently.

  1. 1. Open your Workbook in WPS Spreadsheet: Download and install WPS Office, then open your .xlsm file containing the combo box and shapes.
  2. 2. Enable Macro Execution: Navigate to the 'Developer' tab on the ribbon and click 'Macro Security' to ensure macros are allowed to run.
  3. 3. Access the VBA Editor: Click 'Visual Basic Editor' in the Developer tab to review or modify your ActiveX ComboBox scripts.
  4. 4. Test the Dynamic Image Loading: Exit 'Design Mode' on the ribbon, then interact with your combo box directly in the spreadsheet to see the shape's image update instantly.
Fully compatible with Microsoft Excel Macro-Enabled (.xlsm) filesBuilt-in Visual Basic Editor for writing and debugging macrosSupports ActiveX controls and dynamic shape manipulationLightweight application with fast execution speeds
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my ActiveX combo box triggering the VBA macro?

Ensure that 'Design Mode' is turned off in the Developer tab. ActiveX events and macros will only execute when you are actively using the worksheet, not when it is in editing or design mode.

Can I load images into a shape using standard Data Validation instead of an ActiveX control?

Yes. Instead of using a ComboBox change event, you can use the 'Worksheet_Change' event. Your VBA code must check if the 'Target.Address' matches your data validation cell before executing the image update command.

What happens if the image path in my VBA code is incorrect or the image is missing?

If the specified image file is not found on your device, the VBA code will throw a runtime error. It is best practice to include a 'Dir()' function check in your code to verify the file exists before attempting to load it into the shape.

How do I correctly name a shape in my spreadsheet so my VBA code can target it?

Click on the shape to select it, click inside the Name Box located to the immediate left of the formula bar, type your desired name (such as "PICS"), and press Enter.