VBA & Macro Problems

Fix Excel Macro ObjectThemeColor Error When Changing Shape Color

Natalie TaylorNatalie Taylor Oct 26, 2026 868 views

Question details

The user encounters an out-of-range error with the ObjectThemeColor property when running an Excel VBA macro that was recorded to change a shape's fill color.

How to Fix Excel Macro ObjectThemeColor Error When Running Recorded VBA Code
Product
Microsoft Excel
Device & OS
not provided
Scenario
Executing a recorded VBA macro to automatically apply theme colors to a shape in a worksheet.
Observed behavior
The macro execution stops and displays an out-of-range error on the ObjectThemeColor property, often because a theme constant lacks a valid value or an object library reference is missing.
Before you start

Before modifying your VBA code, press Ctrl + S to save a backup of your current workbook and ensure the Developer tab is visible on your Excel ribbon.

Solution 1Recommended

Add the Microsoft Office Object Library Reference

Enabling the correct Object Library reference ensures that Excel VBA can recognize and correctly apply theme constants like msoThemeColorAccent5.

When recording macros that interact with shapes and theme colors, VBA relies on the Microsoft Office Object Library to understand the theme constants. If this reference is missing or disabled in your workbook, the code will fail to evaluate the colors.

1
Open the VBA Editor

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

2
Access References Menu

In the top menu bar, click on 'Tools' and select 'References' from the dropdown list.

3
Enable the Object Library

Scroll through the available references and check the box next to 'Microsoft Office 16.0 Object Library' (the version number may vary depending on your Office installation).

4
Save and Run

Click 'OK' to apply the changes, close the References dialog, and run your macro again.

Add the Microsoft Office Object Library Reference
Reference Restored: Once the Object Library is added, the theme constant will correctly evaluate, and the out-of-range error should be resolved.
Free Microsoft Office alternative

A Lightweight Alternative for Spreadsheet Management

If you frequently encounter VBA issues or require a reliable, lightweight suite for your data, WPS Office is an excellent free alternative. It offers high compatibility with Microsoft formats, ensuring a seamless transition.

  1. 1. Download and Install: Visit the official WPS Office website to download the free installer and follow the setup instructions.
  2. 2. Open Your Files: Launch WPS Spreadsheet and easily open your existing .xlsx or .xlsm files.
  3. 3. Work Seamlessly: Enjoy familiar spreadsheet features, formulas, and formatting tools without compatibility concerns.
Excellent compatibility with Microsoft Excel (.xlsx, .xlsm, .xls) formatsLightweight and fast installation, saving system resourcesFamiliar user interface with practically no learning curveBuilt-in advanced tools for robust data analysis and visualization
QA img-9

Frequently Asked Questions

What causes the ObjectThemeColor out-of-range error in Excel VBA?

This error typically occurs when the Microsoft Office Object Library reference is missing in the VBA editor, or when the workbook fails to assign a valid numeric value to standard theme color constants like msoThemeColorAccent5.

How do I access the VBA References menu in Excel?

Open the VBA Editor by pressing Alt + F11. Then, click on 'Tools' in the top menu bar, and select 'References' from the dropdown list to manage your active libraries.

Can I avoid using the Selection object for modifying shapes in VBA?

Yes, it is highly recommended to reference shapes directly. You can do this by defining a Shape variable and assigning it the specific shape by name, for example: Set shp = ActiveSheet.Shapes("Rectangle 1"), which greatly improves code reliability.