Working with Page Objects

3 4

A Page object represents a drawing page, which can be either a background or a foreground page. Once you have a reference to a document, you need to get a Page object for the drawing page you want to work with.

If you expect your user to create or display a drawing and then run your program, it's reasonable to assume that the active page contains the drawing you want. You can either get the active page in the Microsoft Visio instance, or you can get the active document and retrieve a page from its Pages collection.

Getting a Page Object

To work with a drawing page, you need to get a reference to a Page object.

Figure 16-2.  <b>Page</b> object and related objects higher in the Visio object model.

Figure 16-2 Page object and related objects higher in the Visio object model.

To get a page from a document, get the Pages collection of the Document or ThisDocument object and get a Page object from the collection. You can get a page by its index within the collection, or if you know the name of the page, you can get it by name. For example, to retrieve a page named Engineering:

 Set pagObj = ThisDocument.Pages.Item("Engineering") 

To get the active page of an application, you can get the ActivePage property of the global or Application object. For example, using the global object:

 Set pagObj = ActivePage 

For details about the global object, see Using the Visio Global Object in Chapter 15, Programming Visio with VBA.

Getting Information about Pages

You can get information about a page by retrieving properties, such as Name and Background, that are displayed in text boxes on the Page Properties tab in the Page Setup dialog box (on the File menu, click Page Setup). The Document property of a page returns the Document object that contains the page.

A Page object also has properties you can use to identify the contents of a drawing page:

  • Shapes returns a collection of all the Shape objects on a page.
  • Connects returns a collection of all the Connect objects on a page.
  • OLEObjects returns a collection of all the OLE 2.0 linked objects, embedded objects, and ActiveX controls on a page.

You can also get information about the dimensions and appearance of a drawing page by getting a Page object's PageSheet property. This property returns a Shape object whose Cells property returns Cell objects that contain the page's formulas. These Cell objects correspond to cells shown in a page's ShapeSheet window.

For example, the following statements return the width of the page:

 Set shpObj = pagObj.PageSheet Set celObj = shpObj.Cells("PageWidth") dWidth = celObj.Result("inches") 

For details about working with formulas, see Chapter 17, Automating Formulas.

Adding Pages to a Drawing

A Visio document can contain more than one page. Each page of a document can 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.

Initially, a new document has one page. To create another page, use the Add method of the document's Pages collection. For example:

 Set pagObj = ThisDocument.Pages.Add 

Once you have added a new page to the collection, you can use the Name property of the Page object to name your page.

Note


In Visio, the pages of a document are displayed in a window. For details on displaying a particular page using Automation, see Displaying Pages of a Document in Working with Document Objects earlier in this chapter.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net