How to Assign a Macro to an Image Across Multiple Excel Worksheets in WPS Office
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.

- 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.
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.
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.
In WPS Spreadsheets, click the Developer tab and select Visual Basic, or press Alt+F11 to open the VBA editor.
In the VBA editor, click Insert > Module, then paste the VBA code into the new module.
In the code, set ws.Shapes("Picture 1").OnAction = "PrintPreviewActiveSheet" using the actual image shape name and your macro name.
Press F5 in the VBA editor or click Run > Run Sub/UserForm, then close the editor.
Return to the worksheet, click the assigned image on any sheet, and confirm that Print Preview opens for the active worksheet.

Add Print Preview to the Quick Access Toolbar Instead of Using Images
Use this when you only need fast Print Preview access and do not require clickable images on every worksheet.
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. Enable the Developer tab in WPS Spreadsheets: Open WPS Office Spreadsheets, click the Menu button, go to Options > Customize Ribbon, and enable Developer.
- 2. Open the VBA editor: Click the Developer tab and select Visual Basic, or press Alt+F11.
- 3. Insert a VBA module: In the editor, click Insert > Module and paste the loop code that references each worksheet and shape.
- 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. Run and test: Run the macro from the VBA editor, then click an image to verify Print Preview opens for the active worksheet.

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.




