Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.81 KB

Excel.ShapeRange.Distribute.md

File metadata and controls

61 lines (45 loc) · 1.81 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
ShapeRange.Distribute method (Excel)
vbaxl10.chm640080
vbaxl10.chm640080
Excel.ShapeRange.Distribute
cef14a4b-4d6e-758e-928a-99233f893ddc
05/14/2019
medium

ShapeRange.Distribute method (Excel)

Horizontally or vertically distributes the shapes in the specified range of shapes.

Syntax

expression.Distribute (DistributeCmd, RelativeTo)

expression A variable that represents a ShapeRange object.

Parameters

Name Required/Optional Data type Description
DistributeCmd Required MsoDistributeCmd Specifies whether shapes in the range are to be distributed horizontally or vertically.
RelativeTo Required MsoTriState Not used in Microsoft Excel. Must be False.

Example

This example defines a shape range that contains all the AutoShapes on myDocument and then horizontally distributes the shapes in this range. The leftmost shape retains its position.

Set myDocument = Worksheets(1) 
With myDocument.Shapes 
    numShapes = .Count 
    If numShapes > 1 Then 
        numAutoShapes = 0 
        ReDim autoShpArray(1 To numShapes) 
        For i = 1 To numShapes 
            If .Item(i).Type = msoAutoShape Then 
                numAutoShapes = numAutoShapes + 1 
                autoShpArray(numAutoShapes) = .Item(i).Name 
            End If 
        Next 
        If numAutoShapes > 1 Then 
            ReDim Preserve autoShpArray(1 To numAutoShapes) 
            Set asRange = .Range(autoShpArray) 
            asRange.Distribute msoDistributeHorizontally, False 
        End If 
    End If 
End With

[!includeSupport and feedback]