Visio2000: Sample Macro to Fit the Page to a Drawing (275589)



The information in this article applies to:

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

This article was previously published under Q275589

SUMMARY

This article contains a sample Microsoft Visual Basic for Applications macro (Sub procedure) to resize any page in a Visio 2000 project to fit the drawing on the page.

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. The following sample Visual Basic macro resizes any page in a project to fit the drawing on the page.

You can use this macro if you want to eliminate extra viewable areas on one or more pages in the project.
  1. In your current Visio project, press ALT+F11 to start the Visual Basic Editor.
  2. On the Insert menu, click Module.
  3. Click View, and then click Code.
  4. Add the following code to the module:
Public Sub FitPageToDrawing()

   Dim visSelection As Visio.Selection
   Dim visShape As Visio.Shape
   Dim width As Double
   Dim height As Double
    
   'Select all the objects on the page.
   ThisDocument.Application.ActiveWindow.SelectAll
    
   'Get the current selection.
   Set visSelection = ThisDocument.Application.ActiveWindow.Selection
    
   'Group the selection.
   visSelection.Group
    
   'Get the new selection from the result of the group operation.
   Set visSelection = ThisDocument.Application.ActiveWindow.Selection
    
   'Get the only shape from the selection.
   Set visShape = visSelection(1)

   'Get the width and height of the group.
   width = visShape.Cells("Width").Result("in")
   height = visShape.Cells("Height").Result("in")
    
    'Set the page width and height.
    ThisDocument.Application.ActivePage.PageSheet.Cells _
       ("PageWidth").Formula = width
    ThisDocument.Application.ActivePage.PageSheet.Cells _
       ("PageHeight").Formula = height
    
    'Ungroup the selection.
    visShape.Ungroup

    'Center the drawing.
    ThisDocument.Application.DoCmd visCmdCenterDrawing

End Sub
				

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