B
Becky N
Hello,
I am trying to create org charts in visio that will be about 40ish pages
long. I am using the wizard to create the charts. Since I am not able to
simply "refresh" the charts by updating my data file I will need to run and
rerun these charts many times. One of the issues I am having is that my chart
is sometimes wider and longer than the page size. I am trying to find some
sort of code (or any solution) that will allow me to shrink the drawing to
the page.
I found some code that is supposed to do this but I am having trouble
piecing it together as it is part of A LOT more code (I have very limited
knowledge in VBA, so I apologize if I don't sound that intelligent with it).
Here are the pieces and parts that I have. Can someone help me put this
together so I can insert it into my document and have it work? I keep getting
"Compile Error: Invalid statement inside type block."
Thanks for your help!
Public Type OrgStruc 'Define user-defined type.
Dim visaddon As Visio.Addon
Dim visdoc As Visio.Document 'Individual Document
Dim winObj As Visio.Window 'Individual Windows
Dim pagsObj As Visio.Pages 'Pages collection
Dim pagObj As Visio.Page 'Page in collection
Dim shpObjs As Visio.Shapes 'Shapes collection
Dim shpObj As Visio.Shape 'Shape in collection
End Type
Sub ChangeZoom()
'Set the object window to be the active window
Set winOjb = ActiveWindow
ActiveWindow.Page = pagObj.Name
'Set the window zoom to be 75%
winObj.Activate
If Not FitsOnPage(pagObj) Then
Set visaddon = ActiveDocument.Application.Addons.Item("OrgC")
visaddon.Run ("/cmd=FitToPage")
End If
'change zoom
'show window as 75% of page
winObj.Zoom = 0.75
End Sub
Private Function FitsOnPage(ovPage As Visio.Page) As Boolean
' Tests if the bounding box enclosing the shapes on the page
' fit within the current page. Note that this does NOT
' take page margins into account!
Dim bFits As Boolean
Dim dLeft As Double
Dim dRight As Double
Dim dTop As Double
Dim dBottom As Double
Dim dWidth As Double
Dim dHeight As Double
' Assume it fits
bFits = True
' Are there any shapes?
If ovPage.Shapes.Count > 0 Then
' Get the bounding box of all of the shapes on the page
' (the values are in 'internal units' -- inches)
ovPage.BoundingBox visBBoxUprightWH, dLeft, dBottom, dRight, dTop
' Check left (must be >= 0)
If dLeft < 0# Then
bFits = False
' Check bottom (must be >= 0)
ElseIf dBottom < 0# Then
bFits = False
' Check right (must be <= page width in internal units)
ElseIf dRight > ovPage.PageSheet.Cells("PageWidth").ResultIU Then
bFits = False
' Check top (must be <= page height in internal units)
ElseIf dTop > ovPage.PageSheet.Cells("PageHeight").ResultIU Then
bFits = False
End If
End If
FitsOnPage = bFits
End Function
I am trying to create org charts in visio that will be about 40ish pages
long. I am using the wizard to create the charts. Since I am not able to
simply "refresh" the charts by updating my data file I will need to run and
rerun these charts many times. One of the issues I am having is that my chart
is sometimes wider and longer than the page size. I am trying to find some
sort of code (or any solution) that will allow me to shrink the drawing to
the page.
I found some code that is supposed to do this but I am having trouble
piecing it together as it is part of A LOT more code (I have very limited
knowledge in VBA, so I apologize if I don't sound that intelligent with it).
Here are the pieces and parts that I have. Can someone help me put this
together so I can insert it into my document and have it work? I keep getting
"Compile Error: Invalid statement inside type block."
Thanks for your help!
Public Type OrgStruc 'Define user-defined type.
Dim visaddon As Visio.Addon
Dim visdoc As Visio.Document 'Individual Document
Dim winObj As Visio.Window 'Individual Windows
Dim pagsObj As Visio.Pages 'Pages collection
Dim pagObj As Visio.Page 'Page in collection
Dim shpObjs As Visio.Shapes 'Shapes collection
Dim shpObj As Visio.Shape 'Shape in collection
End Type
Sub ChangeZoom()
'Set the object window to be the active window
Set winOjb = ActiveWindow
ActiveWindow.Page = pagObj.Name
'Set the window zoom to be 75%
winObj.Activate
If Not FitsOnPage(pagObj) Then
Set visaddon = ActiveDocument.Application.Addons.Item("OrgC")
visaddon.Run ("/cmd=FitToPage")
End If
'change zoom
'show window as 75% of page
winObj.Zoom = 0.75
End Sub
Private Function FitsOnPage(ovPage As Visio.Page) As Boolean
' Tests if the bounding box enclosing the shapes on the page
' fit within the current page. Note that this does NOT
' take page margins into account!
Dim bFits As Boolean
Dim dLeft As Double
Dim dRight As Double
Dim dTop As Double
Dim dBottom As Double
Dim dWidth As Double
Dim dHeight As Double
' Assume it fits
bFits = True
' Are there any shapes?
If ovPage.Shapes.Count > 0 Then
' Get the bounding box of all of the shapes on the page
' (the values are in 'internal units' -- inches)
ovPage.BoundingBox visBBoxUprightWH, dLeft, dBottom, dRight, dTop
' Check left (must be >= 0)
If dLeft < 0# Then
bFits = False
' Check bottom (must be >= 0)
ElseIf dBottom < 0# Then
bFits = False
' Check right (must be <= page width in internal units)
ElseIf dRight > ovPage.PageSheet.Cells("PageWidth").ResultIU Then
bFits = False
' Check top (must be <= page height in internal units)
ElseIf dTop > ovPage.PageSheet.Cells("PageHeight").ResultIU Then
bFits = False
End If
End If
FitsOnPage = bFits
End Function