|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Selection.Align Method (Visio)
Aligns two or more selected shapes.
expression .Align(AlignHorizontal, AlignVertical, GlueToGuide)
expression A variable that represents a Selection object.
Aligns selected shapes along a horizontal axis. See Remarks for possible values.
Aligns selected shapes along a vertical axis. See Remarks for possible values.
If True, creates a guide and glues selected shapes to it; if False, it does not. The default is False.
The following possible values for AlignHorizontal are declared in VisHorizontalSelectionTypes in the Visio type library.
Aligns to the center of the primary selected shape.
Aligns to the left of the primary selected shape.
Does not align horizontally.
Aligns to the right of the primary selected shape.
The following possible values for AlignVertical are declared in VisVerticalSelectionTypes in the Visio type library.
Aligns to bottom of primary selected shape.
Aligns to middle of primary selected shape.
Does not align vertically.
Aligns to top of primary selected shape.
If you pass non-zero values for both AlignHorizontal and AlignVertical, the selected shapes appear superimposed. The most recently created shape appears at the front of the z-order.
Calling the Align method is equivalent to clicking Position on the Home tab and then setting options under Align Shapes.
This Microsoft Visual Basic for Applications (VBA) macro shows how to use the Align method to align three shapes vertically.
Public Sub Align_Example() Dim vsoShape1 As Visio.Shape Dim vsoShape2 As Visio.Shape Dim vsoShape3 As Visio.Shape Set vsoShape1 = Application.ActiveWindow.Page.DrawRectangle(1, 9, 3, 7) Set vsoShape2 = Application.ActiveWindow.Page.DrawRectangle(3, 6, 5, 5) Set vsoShape3 = Application.ActiveWindow.Page.DrawRectangle(6, 4, 8, 2) ActiveWindow.DeselectAll ActiveWindow.Select vsoShape1, visSelect ActiveWindow.Select vsoShape2, visSelect ActiveWindow.Select vsoShape3, visSelect Application.ActiveWindow.Selection.Align visHorzAlignRight, visVertAlignNone, False End Sub