Visio 2002 VBA

  • Thread starter Baffled of Kirkland
  • Start date
B

Baffled of Kirkland

How can I create a VBA macro to save the current page as a .png file at
specific dimensions?
 
J

John Goldsmith

Hello Baffled,

Both the Selection and Page objects have Export methods, so you could select
the shapes you want to export or export all of the shapes on the page or add
another bounding shape that effectively forces the area that's exported to a
specific size.

Have a go with the code below, which you can hopefully adapt to suit your
purpose.

Private Sub ExportAsImage()
'Assumptions are that the bounding box is larger
'than the area of the shapes to export and that
'no shapes sit outside of this area.
Dim sFileName As String
Dim sFileExt As String
Dim sFilePath As String
Dim pag As Page
Dim dblWidth As Double
Dim dblHeight As Double
Dim dblLeftX As Double
Dim dblLeftY As Double
Dim shpBoundingBox As Shape

'Set file strings
sFileName = "MyPngFileName"
sFileExt = ".png"
sFilePath = "C:\Documents and Settings\All Users\Desktop\"

'Get the active page
Set pag = ActivePage

'Set export size in inches
dblWidth = 3
dblHeight = 4

'Set bottom left hand corner of bounding box coordinates
dblLeftX = (pag.PageSheet.CellsU("PageWidth").Result(visInches) _
- dblWidth) / 2
dblLeftY = (pag.PageSheet.CellsU("PageHeight").Result(visInches) _
- dblHeight) / 2

'Draw a bounding box that determines the output image size
Set shpBoundingBox = pag.DrawRectangle(dblLeftX, dblLeftY, _
dblLeftX + dblWidth, dblLeftY + dblHeight)
shpBoundingBox.SendToBack
pag.Export (sFilePath & sFileName & sFileExt)

End Sub


Hope that helps.

Best regards

John


John Goldsmith
www.visualSignals.co.uk
 

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