logo
search
VBA & Macro Problems

How to Change Shape Properties Without Activating a Worksheet in Excel VBA

Emma BrownEmma Brown Oct 21, 2026 868 views

Question details

The user needs to modify a shape's properties on a different Excel worksheet using VBA without making that target worksheet active.

How to Change Shape Properties Without Activating a Worksheet in Excel VBA
Product
Excel
Device & OS
not provided
Scenario
Running a VBA macro that manipulates objects, such as shapes, on inactive worksheets.
Observed behavior
The VBA procedure fails because the code relies on Select or Selection, which requires the target worksheet to be active to work correctly.
Before you start

Verify the exact name of the shape you wish to modify by checking the Name Box in your spreadsheet, and back up your VBA code before applying structural changes.

Solution 1Recommended

Use Direct Object Referencing Instead of Selection

The most robust way to modify shapes in VBA is to reference the worksheet and the shape directly without selecting them first.

Using '.Select' or 'Selection' in VBA is a common cause of runtime errors, as it requires the target worksheet to be the currently active sheet on the screen. By fully qualifying the shape reference, your code will execute faster, run in the background, and will not be interrupted by active window changes.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Locate your macro code

In the Project Explorer panel, double-click the module containing the macro that modifies the shape.

3
Identify the Selection code

Find the lines of code that select the worksheet and shape, such as 'Sheets("Sheet1").Select' followed by 'ActiveSheet.Shapes("Rounded Rectangle 22").Select'.

4
Replace with a direct reference With block

Delete the selection lines and replace them with a direct reference block: 'With Sheet1.Shapes("Rounded Rectangle 22").Fill'. Then, set properties inside the block like '.Visible = msoTrue', '.Transparency = 0', and '.Solid', before closing with 'End With'.

Best Practice: Direct referencing is considered a fundamental best practice in VBA programming. It prevents screen flickering and makes your code significantly cleaner and faster.
Advanced Spreadsheet Tool

Run VBA Macros Smoothly with WPS Spreadsheet

WPS Office Spreadsheet offers robust built-in support for VBA macros. You can seamlessly run and edit your existing Excel VBA scripts, including direct object references, to automate your tasks without any compatibility hurdles.

  1. 1. Open your macro-enabled workbook: Launch WPS Spreadsheet and open your .xlsm file containing the shape macros.
  2. 2. Enable Macros: Click 'Enable Macros' in the security warning prompt at the top of the worksheet to allow script execution.
  3. 3. Access the VBA Editor: Go to the Developer tab and click on 'Visual Basic' or press Alt+F11 to view and edit your object references directly.
  4. 4. Run your modified script: Execute your macro to update shape properties instantly across any inactive worksheet in your workbook.
Full compatibility with Microsoft Excel VBA macros (.xlsm formats)Flawless execution of direct object and shape references across inactive sheetsLightweight architecture for faster macro executionFamiliar Visual Basic editor interface with no learning curve required
microsoft office alternative - wps office

Frequently Asked Questions

Why does my VBA code fail when I use Selection on another sheet?

The Selection object relies on the current active context of the application. If the worksheet containing your shape isn't the active sheet, VBA cannot physically select the shape, which throws a runtime error.

How do I find the correct name of a shape to reference it in VBA?

Click on the shape in your worksheet, then look at the Name Box located to the left of the formula bar. You can use this exact name string inside the Shapes("Name") collection in your VBA code.

Can I modify multiple shape properties at once using direct referencing?

Yes. By using a 'With...End With' block on the specific shape object, you can set multiple properties (like Fill, ForeColor, and Transparency) in a single sequence without VBA having to re-evaluate the object reference each time.