Others

How to Read Visio Page Background Color Using VBA

Muhammad TalhaMuhammad Talha Nov 3, 2026 868 views

Question details

The user needs a VBA macro to programmatically retrieve the RGB color value of a Visio page background that uses a solid fill theme.

How to Read Visio Page Background Color Using VBA
Product
Microsoft Visio
Device & OS
not provided
Scenario
Automating color extraction or inspecting themes applied as solid fills on Microsoft Visio diagram pages.
Observed behavior
Visio page backgrounds are technically stored as shapes on separate attached background pages, requiring a specific VBA approach to access the shape's formula rather than checking the foreground page directly.
Before you start

Ensure you have the Developer tab enabled in Microsoft Visio and that your active foreground page is successfully attached to a background page containing the solid fill.

Solution 1Recommended

Extract Background Color using a VBA Macro

Use this VBA script to access the background page attached to your active page and read the fill formula of its primary background shape.

In Visio, foreground pages do not directly hold a background color property. Instead, the color is rendered from a specific shape located on an attached background page. To get the RGB value, your script must target that specific shape's ShapeSheet formula.

1
Launch the VBA Editor

Open your Visio document, navigate to the Developer tab on the top ribbon, and click 'Visual Basic' to open the VBA Editor.

2
Identify the Background Page

Insert a new module and define a string variable to fetch the name of the attached background page using the code: `Dim bg As String: bg = ActivePage.BackPage`.

3
Inspect the Shape's Fill Formula

Add a print command to target the first shape on that background page and read its foreground fill property: `Debug.Print ActiveDocument.Pages(bg).Shapes(1).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU`.

4
Run and Verify the Result

Run the macro. Check the Immediate Window (Ctrl+G) for the output, which will display the formula governing the background color, commonly formatted like `THEMEGUARD(RGB(255,255,0))`.

Extract Background Color using a VBA Macro
Background Page Verification: Always incorporate error handling in your macro to verify that a background page is actually attached (`ActivePage.BackPage <> ""`) and that the expected shape exists before attempting to access its properties.
Free Microsoft Office alternative

Looking for a Lightweight Diagram and Office Solution?

While managing VBA macros for background shapes is specific to Microsoft Visio, WPS Office offers a highly efficient, free alternative for everyday document creation, spreadsheet analysis, and presentations. Enjoy built-in diagramming utilities and seamless file format support in one compact suite.

Built-in flowchart and diagramming tools for fast, visual document planning.Fully compatible with Microsoft Word, Excel, and PowerPoint file formats.Lightweight architecture that runs smoothly on Windows, Mac, and Linux.Free to use with a familiar, easy-to-navigate tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't the `ActivePage.Background` property give me the background color?

In Microsoft Visio, a foreground page does not natively possess a background color attribute. Instead, backgrounds are separate pages attached to the foreground, containing physical shape objects that hold the fill color data.

How do I manually add a solid background color to a Visio page?

You can add a background color by clicking the Design tab on the ribbon, selecting 'Background', and choosing a Solid Fill color. This action automatically generates the attached background page and shape discussed in the VBA solution.

What does `THEMEGUARD` mean in the Visio VBA color output?

`THEMEGUARD` is a specific function used in Visio ShapeSheet formulas to protect a shape's formatting (such as its RGB fill color) from being overridden by broader document theme changes.

Can I use VBA to change the background color instead of just reading it?

Yes. Instead of using `Debug.Print` to read the formula, you can assign a new value to the shape's cell using a line like `ActiveDocument.Pages(bg).Shapes(1).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "RGB(255,0,0)"` to turn the background red.