Hi
This is the code I have used to resize a page to fit my drawing,
allowing a boundary so the shapes aren't tight against the edge.
One other thing I noticed when doing this is the shapes are no longer
aligned with the grid and this has given me some grief with connection
points. They dont seem to connect if your using a connector, but move
the shape and its all fine.
call FitPageToDrawing(Visio.ActivePage.PageSheet)
Public Sub FitPageToDrawing( _
vsoPageShape As Visio.Shape)
Dim visSelection As Visio.Selection
Dim vsoShape As Visio.Shape
Dim width As Double
Dim height As Double
Dim dl As Double
Dim db As Double
Dim dr As Double
Dim dt As Double
Dim oby As Double
Dim nby As Double
Dim obx As Double
Dim nbx As Double
'Select all the objects on the page.
vsoPageShape.Application.ActiveWindow.SelectAll
'Get the current selection.
Set visSelection = vsoPageShape.Application.ActiveWindow.Selection
'Find the size of the selections bounding box.
Call visSelection.BoundingBox(VisBoundingBoxArgs.visBBoxExtents,
dl, db, dr, dt)
'Get the width and height of the bounding box
width = dr - dl
height = dt - db
'Calculate the page width and height with a 5% boundary
width = width + ((width / 100) * 5)
height = height + ((height / 100) * 5)
'Set the page width and height.
vsoPageShape.Cells("PageWidth").Formula = width
vsoPageShape.Cells("PageHeight").Formula = height
'Calculate old and new centres and move the selection to the centre.
oby = db + ((dt - db) / 2)
obx = dl + ((dr - dl) / 2)
nby = height / 2
nbx = width / 2
Call visSelection.Move(nbx - obx, nby - oby)
vsoPageShape.Application.ActiveWindow.DeselectAll
End Sub