size to fit drawing contents

M

Mike Buraczewski

I am looking for code that will resize a page in the same manner as selecting
"size to fit drawing contents" on the page setup dialog box. Can anyone
help. I am familiar with VB, but totally inept with visio.

Thanks in advance.

Mike B
 
J

JuneTheSecond

You might need grouping all shapes on active page in dorder to get width and
height for the new page size.
Sub test()
Dim shp As Visio.Shape
ActiveWindow.SelectAll
Set shp = ActiveWindow.Selection.Group
ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage,
visPageWidth).FormulaU = shp.Cells("Width").FormulaU
ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage,
visPageHeight).FormulaU = shp.Cells("Height").FormulaU
ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage,
visPageDrawSizeType).FormulaU = "1"
ActivePage.CenterDrawing
shp.Ungroup
End Sub
 
A

Andy

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
 
M

Mark Nelson [MS]

You would also need to iterate through every shape in the page and scale the
text font size. Otherwise you will have larger/smaller shapes with same
size text.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top