Sort/Order related procedures in class Shape (Word VBA)

This page presents procedures from class Shape related to the theme Sort/Order: ZOrder, ZOrderPosition, ShapeRange.ZOrder and ShapeRange.ZOrderPosition

ZOrder

Moves the specified shape in front of or behind other shapes in the collection (that is, changes the shape's position in the z-order).

Use the ZOrderPosition property to determine a shape's current position in the z-order.

Syntax : expression.ZOrder (ZOrderCmd)

ZOrderCmd: Specifies where to move the specified shape relative to the other shapes.

With ActiveDocument.Shapes.AddShape(Type:=msoShapeOval, Left:=100, _ 
 Top:=100, Width:=100, Height:=300) 
 While .ZOrderPosition > 2 
 .ZOrder msoSendBackward 
 Wend 
End With

ZOrderPosition

Returns a Long that represents the position of the specified shape in the z-order.

Shapes(1) returns the shape at the back of the z-order, and Shapes(Shapes.Count) returns the shape at the front of the z-order. This property is read-only. To set the shape's position in the z-order, use the ZOrder method. A shape's position in the z-order corresponds to the shape's index number in the Shapes collection. For example, if there are four shapes on myDocument, the expression myDocument.Shapes(1) returns the shape at the back of the z-order, and the expression myDocument.Shapes(4) returns the shape at the front of the z-order. Whenever you add a new shape to a collection, it is added to the front of the z-order by default.

Set myDocument = ActiveDocument 
With myDocument.Shapes.AddShape(msoShapeOval, 100, 100, 100, 300) 
 While .ZOrderPosition > 2 
 .ZOrder msoSendBackward 
 Wend 
End With

ShapeRange.ZOrder

Moves the specified shape range in front of or behind other shapes in the collection (that is, changes the shape range's position in the z-order).

Use the ZOrderPosition property to determine a shape range's current position in the z-order.

Syntax : expression.ZOrder (ZOrderCmd)

ZOrderCmd: Specifies where to move the specified shape range relative to the other shapes.

Dim sre As ShapeRange: Set sre =  
sre.ZOrder ZOrderCmd:=msoBringToFront

ShapeRange.ZOrderPosition

Returns a Long that represents the position of the specified shape in the z-order.

Shapes(1) returns the shape at the back of the z-order, and Shapes(Shapes.Count) returns the shape at the front of the z-order. This property is read-only. To set the shape's position in the z-order, use the ZOrder method. A shape's position in the z-order corresponds to the shape's index number in the Shapes collection. For example, if there are four shapes on myDocument, the expression myDocument.Shapes(1) returns the shape at the back of the z-order, and the expression myDocument.Shapes(4) returns the shape at the front of the z-order. Whenever you add a new shape to a collection, it is added to the front of the z-order by default.

Dim sre As ShapeRange: Set sre =  
Dim lngZOrderPosition As Long
lngZOrderPosition = sre.ZOrderPosition