VBA & Macro Problems

How to Assign a Macro to an Image Across Multiple Excel Worksheets in WPS Office

Steve KSteve K Nov 13, 2026 869 views

Question details

The user wants to add an image to the same cell on multiple Excel worksheets and assign one macro that opens Print Preview for the active worksheet.

How to Assign a Macro to an Image Across Multiple Excel Worksheets in WPS Office
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
The user manages a multi-sheet Excel workbook and needs clickable images on each sheet to trigger Print Preview.
Observed behavior
The goal is for each worksheet image to run a macro that opens Print Preview for the currently active worksheet.
Before you start

Make sure the workbook is saved as a macro-enabled workbook (.xlsm) and that the Developer tab is visible in WPS Spreadsheets. Check the exact shape name of the image on each worksheet before running the VBA loop.

Solution 1Recommended

Assign a Macro to Images on Multiple Worksheets with VBA

Use this method when images already exist on each sheet and you want the same macro assigned to all of them without updating each image manually.

This method uses the Shape.OnAction property, the VBA property that connects a shape or image to a macro. The code loops through every worksheet and assigns the macro to the image shape with the specified name.

1
Open the VBA editor

In WPS Spreadsheets, click the Developer tab and select Visual Basic, or press Alt+F11 to open the VBA editor.

2
Insert a standard module

In the VBA editor, click Insert > Module, then paste the VBA code into the new module.

3
Set the shape name and macro name

In the code, set ws.Shapes("Picture 1").OnAction = "PrintPreviewActiveSheet" using the actual image shape name and your macro name.

4
Run the assignment macro

Press F5 in the VBA editor or click Run > Run Sub/UserForm, then close the editor.

5
Test an image

Return to the worksheet, click the assigned image on any sheet, and confirm that Print Preview opens for the active worksheet.

Assign a Macro to Images on Multiple Worksheets with VBA
Macro assignment completed: All images with that shape name on every worksheet now run the Print Preview macro when clicked.

Use WPS Spreadsheets VBA to Assign Macros to Images Across Worksheets

WPS Spreadsheets supports VBA macro automation, so you can loop through each worksheet and set the Shape.OnAction property to connect images to the Print Preview macro without assigning each image manually.

  1. 1. Enable the Developer tab in WPS Spreadsheets: Open WPS Office Spreadsheets, click the Menu button, go to Options > Customize Ribbon, and enable Developer.
  2. 2. Open the VBA editor: Click the Developer tab and select Visual Basic, or press Alt+F11.
  3. 3. Insert a VBA module: In the editor, click Insert > Module and paste the loop code that references each worksheet and shape.
  4. 4. Set Shape.OnAction: Use Shape.OnAction = "PrintPreviewActiveSheet" for each image in the loop so every sheet image runs the active-sheet Print Preview macro.
  5. 5. Run and test: Run the macro from the VBA editor, then click an image to verify Print Preview opens for the active worksheet.
Automate image macro assignment across multiple worksheets with VBAOpens Print Preview for the active sheet from a clickable imageWorks with Microsoft Excel macro-enabled workbook files (.xlsm)Free, lightweight WPS Spreadsheets interfaceFamiliar VBA editor and Excel-compatible commands
microsoft office alternative - wps office

Frequently Asked Questions

How do I assign a macro to an image in WPS Spreadsheets?

Select the image, open the VBA editor, and set the shape's OnAction property to the macro name, for example Shapes("Picture 1").OnAction = "MacroName".

Can the same image be added to the same cell on every worksheet?

Yes. You can use a VBA loop to copy the image to the same cell on each worksheet and then set its OnAction property, or add images manually and assign them with a loop.

Why does the image not run the macro after saving?

The workbook must be saved as a macro-enabled workbook (.xlsm). If it is saved as .xlsx, the macro code is removed or blocked.

Is there an easier way than assigning a macro to each image?

Yes. Add the Print Preview command to the Quick Access Toolbar from File > Options > Quick Access Toolbar, then click one icon from any active sheet.

Does this VBA method work in Microsoft Excel?

The Shape.OnAction loop is standard VBA and works in Microsoft Excel and WPS Spreadsheets, but WPS may require the macro-enabled file format and Developer tab.