Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I resize a VISIO page from VBScript

Posted on 2011-09-16
2
1,942 Views
Last Modified: 2012-05-12
Hi Experts,

I'm trying to resize my VISIO Page using the following VBScript code, but page size remains unchanged:

'VBScript for VISIO - Set up a new doc, then resize the page
Dim MyApp, MyTemplate, MyPage, UndoScopeID1
'Set up a new doc
Set MyApp = CreateObject("Visio.Application")
Set MyTemplate = MyApp.Documents.Add("Basic Flowchart.vst")
Set MyPage = MyTemplate.Pages.Item(1)
'Resize the page
UndoScopeID1 = MyApp.BeginUndoScope("Lay Out Shapes")
MyPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU ="680 mm"
MyPage.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageDrawSizeType).FormulaU = "3"
MyPage.PageSheet.CellsSRC(visSectionObject, visRowPageLayout, visPLOResizePage).FormulaForceU = "TRUE"
MyPage.PageSheet.CellsSRC(visSectionObject, visRowPageLayout, visPLOAvenueSizeX).FormulaForceU = "9.25 mm"
MyPage.Layout
MyApp.EndUndoScope UndoScopeID1, True

The last few lines of code are derived from a macro recorded in VISIO.  The macro itself works OK:

Dim UndoScopeID1 As Long
  UndoScopeID1 = Application.BeginUndoScope("Lay Out Shapes")
  Application.ActiveWindow.Page.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageHeight).FormulaU = "640.825 mm"
  Application.ActiveWindow.Page.PageSheet.CellsSRC(visSectionObject, visRowPage, visPageDrawSizeType).FormulaU = "3"
  Application.ActiveWindow.Page.PageSheet.CellsSRC(visSectionObject, visRowPageLayout, visPLOResizePage).FormulaForceU = "TRUE"
  Application.ActiveWindow.Page.PageSheet.CellsSRC(visSectionObject, visRowPageLayout, visPLOAvenueSizeX).FormulaForceU = "9.525 mm"
  Application.ActiveWindow.Page.Layout
  Application.EndUndoScope UndoScopeID1, True

Please help.

0
Comment
Question by:AnwaPeck
2 Comments
 
LVL 11

Accepted Solution

by:
Visio_Guy earned 500 total points
ID: 36548417
Hi AP,

Visio's recorder-generated macros are hard to re-use without lots of cleanup. Here's a cleaner sample of resizing pages in Visio. Keep in mind that there are several ways to get a page object (such as doc.Pages(3) instead of Visio.ActivePage).

Also, if you are setting your page size to a standard-size piece of paper, then the settings might be different than what I've shown here. The code snippet below is for an arbitrary sized drawing page.

If you switch on Developer mode, you can right-click a page and choose Show ShapeSheet. There you can see which cells change when you change the size of a page via Page Setup, and modify the code below, accordingly.

Hopefully this snippet is clearer than the recorder macro above, and will show you the essentials of what you need to know.

Sub ResizePage()

  '// Get a Visio page object. There are several ways to
  '// do this, but we'll just start with the active page:
  Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  
  '// Get the ShapeSheet for the page:
  Dim shpPg As Visio.Shape
  Set shpPg = pg.PageSheet
  
  '// Set cells in the ShapeSheet to control the page size:
  shpPg.CellsU("PageWidth").ResultIU = 12 '...Note: IU means inches!
  shpPg.CellsU("PageHeight").ResultIU = 3
  
  '// To set the page size in millimeters, you would do this:
  'shpPg.CellsU("PageWidth").Result(Visio.VisUnitCodes.visMillimeters) = 600
  'shpPg.CellsU("PageHeight").Result(Visio.VisUnitCodes.visMillimeters) = 600
  
  '// If the page size is irregular, you should set the size
  '// type to 'custom'.
  shpPg.CellsU("DrawingSizeType").ResultIU = 3 '...visCustom
  
  '// Turn off auto-sizing pages:
  '// Visio 2010 only!
  If (pg.Application.Version >= 14) Then
    shpPg.CellsU("DrawingResizeType").ResultIU = 2 '...visAutoSizeOff
  End If
  
End Sub

Open in new window

0
 

Author Closing Comment

by:AnwaPeck
ID: 36548849
Visio_Guy!!!!

Excellent.  And the clear guidelines are much appreciated.

My new working VBScript. (I could not find a way to use the vis* properties in my VBScript to resize in millimeters, but I can get by with inches for now):

'VBScript for VISIO
Dim MyApp, MyTemplate, MyPage, MyShpPage
'Create new Visio Page Object
Set MyApp = CreateObject("Visio.Application")
Set MyTemplate = MyApp.Documents.Add("Basic Flowchart.vst")
Set MyPage = MyApp.ActivePage
Set MyShpPage = MyPage.PageSheet
'Resize the page (and set size type to CUSTOM)
MyShpPage.CellsU("PageWidth").ResultIU = 24
MyShpPage.CellsU("PageHeight").ResultIU = 24
MyShpPage.CellsU("DrawingSizeType").ResultIU = 3

Thank You.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Flow diagrams - export sizing issue 6 54
SQL Server Express 2014 Master / Slave database replication 4 662
dialer.exe 4 63
.NET tools for adding thread safety to a web app? 3 48
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question