Visio2000: Sample Macro to Navigate to Pages Within a Drawing (278932)



The information in this article applies to:

  • Microsoft Visio 2000 Standard Edition
  • Microsoft Visio 2000 Professional Edition
  • Microsoft Visio 2000 Technical Edition
  • Microsoft Visio 2000 Enterprise Edition

This article was previously published under Q278932

SUMMARY

The following Microsoft Visual Basic for Applications macro (Sub procedure) demonstrates how to navigate to different pages in Microsoft Visio by using a page's name or index.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Use the Name Property

To go to a page by using its Name property, use the Application.Page property:
Sub GoToPageByName()
 
   On Error GoTo ErrorHandler    ' Enable error-handling routine.
   
   ActiveWindow.Page = "Page-2"
   MsgBox ("You are now on Page-2 of the drawing.")
   
   Exit Sub        ' Exit to avoid error handler when no error occurred.
   
   ErrorHandler:              ' Error-handling routine.
   MsgBox ("Your drawing does not have a page called Page-2.")

End Sub
				

Use the Page Index

To go to a page by its page index, use the GetNames method to fill an array; then use the array's index value as the argument for the ActiveWindow.Page property:
Public Sub GoToPageByIndex()

   Dim PageNamesArray() As String
    
   On Error GoTo ErrorHandler    ' Enable error-handling routine.
   ActiveDocument.Pages.GetNames PageNamesArray
    
   ' The array start with 0 for Page-1.
   ' Index the array to Page-2 in the Drawing
   ActiveWindow.Page = PageNamesArray(1)
   MsgBox ("You are now on Page-2 of the drawing.")
    
   Exit Sub        ' Exit to avoid error handler when no error occurred.
   
   ErrorHandler:                    ' Error-handling routine.
   MsgBox ("Your drawing does not have a second page.")

End Sub
				

REFERENCES

For additional information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

277011 Visio2000: How to Run Sample Code from Knowledge Base Articles

Or, go to the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto KB278932