Background Pages

A Microsoft® Visio® document can contain more than one page. Each page of a document may contain a unique drawing, and some pages can serve as backgrounds to other pages.

You can create multiple-page documents from a program by adding pages and assigning backgrounds to them. You can also change page settings, such as the drawing scale and page width and height.

In this section…

Creating and Assigning Background Pages

Iterating through the Pages Collection: an Example

Setting up Pages and Backgrounds: an Example

Changing Page Settings

Creating and Assigning Background Pages

When you want the same arrangement of shapes to appear in more than one drawing, you can place the shapes on a background page. For example, if your program creates drawings on multiple pages, you might create a background page with header and footer shapes, or title block and border shapes.

The same background page can be assigned to any number of foreground pages. And although a foreground page can have only one background page, a background page can have its own background page, so it's possible to construct a drawing of many background pages. To create a background page, add a page to the drawing and set its Background property to True. For example:

backPagObj.Background = True

To assign the background page to another page so that the background's shapes appear in the drawing window when that page is displayed, set the foreground page's BackPage property to the name of the background page. For example:

pagObj.BackPage = "Floor Plan"

TOP

Iterating through the Pages Collection: an Example

The items in a Pages collection are indexed starting with foreground pages in the order they are listed in the Reorder Pages dialog box, followed by background pages in arbitrary order. (To view the Reorder Pages dialog box, right-click any page tab in the drawing window, and then click Reorder Pages.)

The following example iterates through the Pages collection of the active document and lists the names of all foreground pages in a listbox on a user form.

Sub IteratePages ()     Dim pagsObj As Visio.Pages     Dim pagObj As Visio.Page     Set pagsObj = ThisDocument.Pages     UserForm1.ListBox1.Clear     For Each pagObj In pagsObj         If pagObj.Background = False Then             UserForm1.ListBox1.AddItem pagObj.Name         End If     Next     UserForm1.Show End Sub

TOP

Setting up Pages and Backgrounds: an Example

The CreateAndAssignBackground procedure creates one foreground page and one background page and then assigns the new background page to the new foreground page.

'Paste CreateAndAssignBackground in the ThisDocument 'code window and then run the procedure

Public Sub CreateAndAssignBackground()

    Dim pgForeGround As Visio.Page     Dim pgBackGround As Visio.Page     Dim szBackGroundPageName As String

    'Add new page to active document     Set pgForeGround = ActiveDocument.Pages.Add

'Add new page for background to active document Set pgBackGround = ActiveDocument.Pages.Add

'Set the Background property to True pgBackGround.Background = True

    'Get the background page name     szBackGroundPageName = pgBackGround.Name

    'Assign the background page to     'the foreground page     pgForeGround.BackPage = szBackGroundPageName

End Sub

TOP

Changing Page Settings

For Visio solutions, Microsoft® Visual Basic® for Applications (VBA) programs usually use a Visio template to create a drawing. The template can provide the correct settings for the drawings created by your program, so you might not need to change settings such as the drawing scale or page scale. If you need to change these settings, or if you create a drawing without using a template but don't want to use the Visio defaults, you can change the page settings by changing page formulas.

To change a page formula, get the PageSheet property of a Page object, which returns a Shape object that represents a page's formulas. You then use the Cells property of this Shape object to retrieve a page cell by name, as you would retrieve cells for shapes on the drawing page.

A Master object also has a PageSheet property that you can use to get the same settings—drawing scale, page scale, and so on—for the master as you can for the page. You might do this, for example, to determine whether the scale of a master is appropriate for the drawing page before you drop the master onto the drawing page.

Note You can also access page settings by getting a special shape called ThePage from both the Page and Master objects' Shapes collections. This is the equivalent of getting the PageSheet property of a Page or Master object.

For example, suppose your program allows the user to change the scale of a space plan from your program rather than from the Visio engine. The following statements set the scale of pagObj so that 1 foot in the drawing equals 1/8 inch on the drawing page:

Set pagSheetObj = pagObj.PageSheet Set pagCelPageScale = pagSheetObj.Cells("PageScale") Set pagCelDrawScale = pagSheetObj.Cells("DrawingScale") pagCelPageScale.Result("in") = 0.125 pagCelDrawScale.Result("ft") = 1.0

The page cells you're mostly likely to work with are those that control the drawing's size and scale. Other page cells control the fineness of the rulers and the grid, the layers defined for the page, actions, and user-defined cells. For a list of page sections and cells, see Appendix B, ShapeSheet Section, Row, and Cell Indices.