Visio Background Check

Another interesting question from the Visio section of Answers. The user wanted to find the background colour of a page. He was using the Backgrounds tab on the Design ribbon. This creates a background page with a name like VBackground-1. So, what he was looking for was the colour of the first shape on the background page.

One unique feature of the background pages that Visio creates is that the background page can be used by foreground pages of different sizes. So,how does it do that? By using these formulaes in the Shape Transform section of the shape.

The “ThePage” refers to the foreground page, not the background page it may be on. Background pages can have background pages, so the shape you are looking for may be nested.

Similar formulas can be used in other parts of the shape so that a fixed size title block can be created for various page sizes. It is just a matter of positioning the title block relative to an edge of the page.

So, with VBA how do you find the colour? On the foreground page,
will give you the name of the background page and

Dim pagnam As String
pagnam = ActivePage.BackPage
Debug.Print "Name of the first shape on the background page = "; ActiveDocument.Pages(pagnam).Shapes(1).Name
Debug.Print "Colour of the shape on the background page = "; ActiveDocument.Pages(pagnam).Shapes(1).CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU

Will give you the name of the page and the fill colour.

Of course, this is not a universal solution. There may not be a background page and the background page may not contain a rectangle of colour or the colour shape is not the first shape on the page.

The code should also verify that objects referenced exist.

Published by johnvisiomvp

The original Visio MVP. I have worked with the Visio team since 1993