Page setup for multiple page files

D

downstage

Hiya,

I have around 60 visio pages for a current project, divided into a number of
files each of which containts anything up to 16 pages.

I want to print these two or four per page (using my printer properties) on
an A4 page. Currently they are all set to A3.

I know how to do this for an individual page; I go to page stup and choose
'printer paper > A4' and 'fit to 1 sheet' in print setup tab, then 'size to
fit drawing contents' in page size tab (unless there's a better way to do it).

However, this is rather long-winded when you're doing it for each of 16
pages in one file.

Is there a simpler way, or a way to change the page setup of all pages in
one file?

Thanks in advance for any help.
 
J

John Goldsmith

Hello downstage,

A little code might help take some of the leg work out of this. If you've
not tried using code or macros before then this is an excellent project to
get started on.

Here's a quick walkthrough:

1) Copy the code below to the clipboard

2) Open your first document and press Alt + F11 to open the VBE code editor
(see http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html
for a bit of background)

3) Double click the 'ThisDocument' node in the Project Explorer treeview and
paste the code into the pane on the right.

4) You can now run the code by pressing the F5 key or selecting
'ChangePageSetup' from Tools / Macro / ThisDocument / ChangePageSetup

5) Repeat the above for each of your subsequent documents.

Sub ChangePageSetup()
Dim pag As Page
'Run through each page in document
For Each pag In ThisDocument.Pages
With pag
'Set 'Fit to' values
.PageSheet.CellsU("PagesX").FormulaU = "2"
.PageSheet.CellsU("PagesY").FormulaU = "2"
.PageSheet.CellsU("OnPage").FormulaU = "1"

'Set printer page size
.PageSheet.CellsU("PaperKind").FormulaU = "9"

'Set Drawing page size
.PageSheet.CellsU("PageWidth").FormulaU = "297 mm"
.PageSheet.CellsU("PageHeight").FormulaU = "420 mm"
End With
Next pag
End Sub


Anyway, I hope I've understood your problem correctly, so have a go and let
me know how you get on. you might want to have a go on a copy of your
document just in case!

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
D

downstage

Hi John,

Thanks for your useful reply. I'd never thought to use code or macros in
Visio before.

However, being a beginner in the programming world I need a little more
advice... The code you supplied is great but I've adjusted the page setup
values. I looked on your webpage and saw what you'd written about the Macro
recorder. I ussed that to get the code for the exact page setup I require,
and have ended up with the following (not quite as neat as yours!):

Sub pagesetup()
' Keyboard Shortcut: Ctrl+q
'

Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Page Setup")
Application.ActivePage.Background = False
Application.ActivePage.BackPage = ""
Application.ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage,
visPageWidth).FormulaU = "289.61471226343 mm"
Application.ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage,
visPageHeight).FormulaU = "416.71748263889 mm"
Application.ActivePage.PageSheet.CellsSRC(visSectionObject, visRowPage,
visPageDrawSizeType).FormulaU = "1"
Application.ActivePage.PageSheet.CellsSRC(visSectionObject,
visRowPrintProperties, visPrintPropertiesOnPage).FormulaU = "1"
Application.ActivePage.PageSheet.CellsSRC(visSectionObject,
visRowPrintProperties, visPrintPropertiesPaperKind).FormulaU = "9"
Application.EndUndoScope UndoScopeID1, True

End Sub

This is great and, given that you can assign a shortcut key, will already
save a great deal of time.

What I'd like to do though is add the command to apply to each page in the
document as you did, but I'm not sure where it would fit into my code. Could
you advise?

Thanks again for your help,
downstage
 
J

John Goldsmith

Well John Marshall has a nice post on the macro recorder that you might want
to have a look at:

http://msmvps.com/blogs/visio/archive/2006/03/03/85364.aspx

In terms of what you've recorded, you can see from the code that the macro
recorder doesn't really have much of a concept of what's just happened or
what's about to happen. It just keeps track of each individual action. The
result is that you usually end up with an 'active' object of some
description, which in your case is the ActivePage object. This needs to be
replaced or refered to in a different way otherwise you'd have to deal with
making each page active just to use it, which seems a little wasteful.

So instead of refering to the ActivePage my code below creates a temporary
Page object ('pag') and then assigns it to reference each of the document's
pages in turn using the For Each mechanism. You just need to wrap your
recorded code inside the loop.....

Sub pagesetup()
' Keyboard Shortcut: Ctrl+q
'
Dim pag As Page
Dim UndoScopeID1 As Long
'Run through each page in document
UndoScopeID1 = Application.BeginUndoScope("Page Setup")
For Each pag In ThisDocument.Pages
With pag
.PageSheet.CellsSRC( _
visSectionObject, _
visRowPage, _
visPageWidth).FormulaU = "289 mm"
.PageSheet.CellsSRC( _
visSectionObject, _
visRowPage, _
visPageHeight).FormulaU = "416 mm"
.PageSheet.CellsSRC( _
visSectionObject, _
visRowPage, _
visPageDrawSizeType).FormulaU = "1"
.PageSheet.CellsSRC( _
visSectionObject, _
visRowPrintProperties, _
visPrintPropertiesOnPage).FormulaU = "1"
.PageSheet.CellsSRC( _
visSectionObject, _
visRowPrintProperties, _
visPrintPropertiesPaperKind).FormulaU = "9"
End With
Next pag
Application.EndUndoScope UndoScopeID1, True
End Sub

Try this and let me know if you have any other questions.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
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