VBA & Macro Problems

Resize an Excel Shape on Click Using VBA

Jason MillerJason Miller Nov 22, 2026 868 views

Question details

The user wants to enlarge a picture-filled shape in Excel when clicked and restore its original size on the next click.

Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains shapes that should toggle between their original and enlarged dimensions when selected.
Observed behavior
Clicking an assigned shape should enlarge it, and clicking it again should restore its original dimensions.
Before you start

Check that each shape's original height is greater than 25 and no more than 50 points for the threshold-based macro below. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file.

Solution 1Recommended

Assign a VBA toggle macro to each Excel shape

Use one macro to identify the clicked shape and toggle its height and width between their original and doubled sizes.

Application.Caller identifies the shape that started the macro. The 50-point threshold works when each shape's original height is greater than 25 and no more than 50 points; an enlarged shape will then be taller than 50 points.

1
Open the VBA editor

In Excel, select Developer > Visual Basic, then choose Insert > Module.

2
Add the toggle macro

Paste this code into the module: Sub AdjustShape() Dim shapeObject As Shape Dim change As Double Dim originalLock As MsoTriState Set shapeObject = ActiveSheet.Shapes(Application.Caller) If shapeObject.Height > 50 Then change = 0.5 Else change = 2 End If originalLock = shapeObject.LockAspectRatio shapeObject.LockAspectRatio = msoFalse shapeObject.Height = shapeObject.Height * change shapeObject.Width = shapeObject.Width * change shapeObject.LockAspectRatio = originalLock End Sub

3
Assign the macro

Return to the worksheet, right-click a shape, select Assign Macro, choose AdjustShape, and select OK. Repeat for each shape you want to resize.

4
Test the toggle

Click an assigned shape once to double its size, then click it again to restore its original height and width.

Assign a VBA toggle macro to each Excel shape
Shapes outside the height range: If original shape heights do not fall within the specified range, adjust the threshold for your shapes or use a macro that stores each shape's original dimensions. Running this macro from the VBA editor instead of clicking an assigned shape will not provide the expected caller.
Free Microsoft Office alternative

Work with spreadsheet shapes in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for easier migration. You can work with shapes in WPS Spreadsheets, although this Excel VBA click-to-resize macro is specific to Excel and macro support may vary by WPS version.

Insert and resize shapes in spreadsheetsOpen and edit Microsoft Excel formats such as XLSX and XLSUse a familiar interface for everyday spreadsheet tasksGet started with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

How does the macro know which shape I clicked?

After you assign the macro through the shape's right-click menu, Application.Caller returns the caller's name. ActiveSheet.Shapes(Application.Caller) uses that name to find the clicked shape.

Why does my shape shrink on the first click?

The example treats a height above 50 points as already enlarged. Check the shape's height and adjust the threshold or use a method that stores its original dimensions.

Do I need a separate macro for every shape?

No. Assign the same AdjustShape macro to each shape using right-click > Assign Macro. The macro uses Application.Caller to identify the shape that was clicked.

What file format should I use to keep the VBA code?

In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm). Enable macros when opening the file only if you trust its source.