Microsoft KB Archive/289859

= Visio2000: Sample Macro to Duplicate a Page =

Article ID: 289859

Article Last Modified on 1/31/2007

-

APPLIES TO


 * Microsoft Visio 2000 Standard Edition
 * Microsoft Visio 2000 Professional Edition
 * Microsoft Visio 2000 Technical Edition
 * Microsoft Visio 2000 Enterprise Edition

-



This article was previously published under Q289859



For a Microsoft Visio 2002 version of this article, see 290581.



SUMMARY
This article explains how to duplicate a page, along with the shapes on that particular page, by using Microsoft Visual Basic for Applications. The sample code also provides an example of how to use the Page.PageSheet property to get access to a page's ShapeSheet cells.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Sample Code
The following sample code duplicates a page: Public Sub DuplicateActivePage Dim OriginalPage As Visio.Shape Dim DuplicatePage As Visio.Shape Dim ShapeDropX As Double Dim ShapeDropY As Double Set OriginalPage = ActivePage.PageSheet ActiveWindow.SelectAll ' Select everything on the first page...   ActiveWindow.Group ' ...then group it all...    ActiveWindow.Copy ' ... then copy it to the Clipboard. ShapeDropX = ActiveWindow.Selection(1).Cells(&quot;PinX&quot;) ' Get the new Group's x position.

ShapeDropY = ActiveWindow.Selection(1).Cells(&quot;PinY&quot;) ' Get the new Group's y position. Set DuplicatePage = ActiveDocument.Pages.Add.PageSheet ' Create the new page. ' Set attributes of the new page to be the same as the original page. With DuplicatePage .Cells(&quot;PageWidth&quot;) = OriginalPage.Cells(&quot;PageWidth&quot;) .Cells(&quot;PageScale&quot;) = OriginalPage.Cells(&quot;PageScale&quot;) .Cells(&quot;ShdwOffsetX&quot;) = OriginalPage.Cells(&quot;ShdwOffsetX&quot;) .Cells(&quot;PageHeight&quot;) = OriginalPage.Cells(&quot;PageHeight&quot;) .Cells(&quot;DrawingScale&quot;) = OriginalPage.Cells(&quot;DrawingScale&quot;) .Cells(&quot;ShdwOffsetY&quot;) = OriginalPage.Cells(&quot;ShdwOffsetY&quot;) .Cells(&quot;DrawingSizeType&quot;) = OriginalPage.Cells(&quot;DrawingSizeType&quot;) .Cells(&quot;DrawingScaleType&quot;) = OriginalPage.Cells(&quot;DrawingScaleType&quot;) .Cells(&quot;InhibitSnap&quot;) = OriginalPage.Cells(&quot;InhibitSnap&quot;) .Cells(&quot;PlaceStyle&quot;) = OriginalPage.Cells(&quot;PlaceStyle&quot;) .Cells(&quot;PlaceDepth&quot;) = OriginalPage.Cells(&quot;PlaceDepth&quot;) .Cells(&quot;PlowCode&quot;) = OriginalPage.Cells(&quot;PlowCode&quot;) .Cells(&quot;ResizePage&quot;) = OriginalPage.Cells(&quot;ResizePage&quot;) .Cells(&quot;DynamicsOff&quot;) = OriginalPage.Cells(&quot;DynamicsOff&quot;) .Cells(&quot;EnableGrid&quot;) = OriginalPage.Cells(&quot;EnableGrid&quot;) .Cells(&quot;CtrlAsInput&quot;) = OriginalPage.Cells(&quot;CtrlAsInput&quot;) .Cells(&quot;LineAdjustFrom&quot;) = OriginalPage.Cells(&quot;LineAdjustFrom&quot;) .Cells(&quot;BlockSizeX&quot;) = OriginalPage.Cells(&quot;BlockSizeX&quot;) .Cells(&quot;BlockSizeY&quot;) = OriginalPage.Cells(&quot;BlockSizeY&quot;) .Cells(&quot;AvenueSizeX&quot;) = OriginalPage.Cells(&quot;AvenueSizeX&quot;) .Cells(&quot;AvenueSizeY&quot;) = OriginalPage.Cells(&quot;AvenueSizeY&quot;) .Cells(&quot;RouteStyle&quot;) = OriginalPage.Cells(&quot;RouteStyle&quot;) .Cells(&quot;PageLineJumpDirX&quot;) = OriginalPage.Cells(&quot;PageLineJumpDirX&quot;) .Cells(&quot;PageLineJumpDirY&quot;) = OriginalPage.Cells(&quot;PageLineJumpDirY&quot;) .Cells(&quot;LineAdjustTo&quot;) = OriginalPage.Cells(&quot;LineAdjustTo&quot;) .Cells(&quot;LineToNodeX&quot;) = OriginalPage.Cells(&quot;LineToNodeX&quot;) .Cells(&quot;LineToNodeY&quot;) = OriginalPage.Cells(&quot;LineToNodeY&quot;) .Cells(&quot;LineToLineX&quot;) = OriginalPage.Cells(&quot;LineToLineX&quot;) .Cells(&quot;LineToLineY&quot;) = OriginalPage.Cells(&quot;LineToLineY&quot;) .Cells(&quot;LineJumpFactorX&quot;) = OriginalPage.Cells(&quot;LineJumpFactorX&quot;) .Cells(&quot;LineJumpFactorY&quot;) = OriginalPage.Cells(&quot;LineJumpFactorY&quot;) .Cells(&quot;LineJumpCode&quot;) = OriginalPage.Cells(&quot;LineJumpCode&quot;) .Cells(&quot;LineJumpStyle&quot;) = OriginalPage.Cells(&quot;LineJumpStyle&quot;) .Cells(&quot;XRulerOrigin&quot;) = OriginalPage.Cells(&quot;XRulerOrigin&quot;) .Cells(&quot;YRulerOrigin&quot;) = OriginalPage.Cells(&quot;YRulerOrigin&quot;) .Cells(&quot;XRulerDensity&quot;) = OriginalPage.Cells(&quot;XRulerDensity&quot;) .Cells(&quot;YRulerDensity&quot;) = OriginalPage.Cells(&quot;YRulerDensity&quot;) .Cells(&quot;XGridOrigin&quot;) = OriginalPage.Cells(&quot;XGridOrigin&quot;) .Cells(&quot;YGridOrigin&quot;) = OriginalPage.Cells(&quot;YGridOrigin&quot;) .Cells(&quot;XGridDensity&quot;) = OriginalPage.Cells(&quot;XGridDensity&quot;) .Cells(&quot;YGridDensity&quot;) = OriginalPage.Cells(&quot;YGridDensity&quot;) .Cells(&quot;XGridSpacing&quot;) = OriginalPage.Cells(&quot;XGridSpacing&quot;) .Cells(&quot;YGridSpacing&quot;) = OriginalPage.Cells(&quot;YGridSpacing&quot;) End With ActivePage.Paste ' Paste the copied group from the Clipboard. ActiveWindow.Selection(1).Cells(&quot;PinX&quot;) = ShapeDropX 'Position the group. ActiveWindow.Selection(1).Cells(&quot;PinY&quot;) = ShapeDropY ActiveWindow.Selection(1).Ungroup 'Ungroup the group. ActiveWindow.Page = OriginalPage.ContainingPage.Name ' Go back to the original page...

ActiveWindow.SelectAll ' ...then select the group...   ActiveWindow.Selection(1).Ungroup '...and ungroup it...    ActiveWindow.DeselectAll ' and then deselect all of the shapes. MsgBox DuplicatePage.ContainingPage.Name & &quot; has been created.&quot; End Sub

