How to Read Visio Page Background Color Using VBA
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.

- 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.
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.
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.
Open your Visio document, navigate to the Developer tab on the top ribbon, and click 'Visual Basic' to open the VBA Editor.
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`.
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`.
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))`.

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.

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.




