Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of


Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Bringing certain shapes on top of others in your slides


A user on the PowerPoint newsgroup needed a way of making sure that certain shapes in his presentation were always on top of the other shapes on each slide, and that they were always "stacked" in a certain order.

In this case, all arrows were to be on top, all text boxes below the arrows, all pictures below the text boxes and everything else on the slide below that.

At first glance this seems easy: step through all of the shapes on each slide once for each type of shape, and if the shape is the type we're searching for, bring it to the top.

Unfortunately, this doesn't work, because the order of the shape collection gets changed each time you change the "stacking order".

Instead, we get a reference to each shape that meets our criteria, put it in an array, then once we've checked all the shapes, process the array, moving each shape to the top in order.


Sub StackEmDanO()

Dim oShapes As Shapes
Dim oSh As Shape
Dim oSl As Slide
Dim x As Long
Dim aShapes() As Shape

For Each oSl In ActivePresentation.Slides
' Redimension the array to hold the maximum number of shapes for this slide
ReDim aShapes(1 To oSl.Shapes.Count) As Shape
x = 1

' Add the shapes we want to affect to the array of shapes
' in the order we want them stacked

' Pictures
For Each oSh In oSl.Shapes
If oSh.Type = msoPicture Then
Set aShapes(x) = oSh
x = x + 1
End If
Next ' shape
' Textboxes
For Each oSh In oSl.Shapes
If oSh.Type = msoTextBox Then
Set aShapes(x) = oSh
x = x + 1
End If
Next ' shape
' Lines that have an arrowhead
For Each oSh In oSl.Shapes
If oSh.Type = msoLine Then
If oSh.Line.EndArrowheadStyle <> msoArrowheadNone _
Or _
oSh.Line.BeginArrowheadStyle <> msoArrowheadNone Then

Set aShapes(x) = oSh
x = x + 1
End If
End If
Next ' shape

' Now bring each shape in the array to the top
' in order
For x = 1 To UBound(aShapes)
If Not aShapes(x) Is Nothing Then
aShapes(x).ZOrder (msoBringToFront)
Debug.Print aShapes(x).Name
End If
Next ' slide

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Search terms:order,shape,stack,z

Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Bringing certain shapes on top of others in your slides
Last update 07 June, 2011