Range Method

Applies To

Shapes collection object, Slides collection object.

Description

Shapes object: Returns a ShapeRange object that represents a subset of the shapes in a Shapes collection.

Slides object: Returns a SlideRange object that represents a subset of the slides in a Slides collection.

Syntax

expression.Range(Index)

expression Required. An expression that returns either a Shapes or Slides object.

Index Optional Variant. The individual shapes or slides that are to be included in the range. Can be an integer that specifies the index number of the shape or slide, a string that specifies the name of the shape or slide, or an array that contains either integers or strings. If this argument is omitted, the Range method returns all the objects in the specified collection.

Remarks

Although you can use the Range method to return any number of shapes or slides, it's simpler to use the Item method if you only want to return a single member of the collection. For example, Shapes(1) is simpler than Shapes.Range(1), and Slides(2) is simpler than Slides.Range(2).

To specify an array of integers or strings for Index, you can use the Array function. For example, the following instruction returns two shapes specified by name.

Set myRange = myDocument.Shapes.Range(Array("Oval 4", "Rectangle 5"))
See Also

TextRange property.

Example

This example sets the fill pattern for shapes one and three on myDocument.

Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.Range(Array(1, 3)).Fill.Patterned msoPatternHorizontalBrick
This example sets the fill pattern for the shapes named "Oval 4" and "Rectangle 5" on myDocument.

Set myDocument = ActivePresentation.Slides(1)
Set myRange = myDocument.Shapes.Range(Array("Oval 4", "Rectangle 5"))
myRange.Fill.Patterned msoPatternHorizontalBrick
This example sets the fill pattern for all shapes on myDocument.

Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.Range.Fill.Patterned msoPatternHorizontalBrick
This example sets the fill pattern for shape one on myDocument.

Set myDocument = ActivePresentation.Slides(1)
Set myRange = myDocument.Shapes.Range(1)
myRange.Fill.Patterned msoPatternHorizontalBrick
This example creates an array that contains all the AutoShapes on myDocument, uses that array to define a shape range, and then distributes all the shapes in that range horizontally.

Set myDocument = ActivePresentation.Slides(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
This example sets the title color for slides one and three in myDocument.

Set mySlides = ActivePresentation.Slides.Range(Array(1, 3))
mySlides.ColorScheme.Colors(ppTitle).RGB = RGB(0, 255, 0)
This example sets the title color for the slides named "Slide6" and "Slide8" in myDocument.

Set mySlides = ActivePresentation.Slides.Range(Array("Slide6", "Slide8"))
mySlides.ColorScheme.Colors(ppTitle).RGB = RGB(0, 255, 0)
This example sets the title color for all the slides in the active presentation.

Set mySlides = ActivePresentation.Slides.Range
mySlides.ColorScheme.Colors(ppTitle).RGB = RGB(255, 0, 0)
This example creates an array that contains all the title slides in the active presentation, uses that array to define a slide range, and then sets the title color for all slides in that range.

Dim MyTitleArray() As Long
Set pSlides = ActivePresentation.Slides
ReDim MyTitleArray(1 To pSlides.Count)
For Each pSlide In pSlides
    If pSlide.Layout = ppLayoutTitle Then
        nCounter = nCounter + 1
        MyTitleArray(nCounter) = pSlide.SlideIndex
    End If
Next pSlide
ReDim Preserve MyTitleArray(1 To nCounter)
Set rngTitleSlides = ActivePresentation.Slides.Range(MyTitleArray)
rngTitleSlides.ColorScheme.Colors(ppTitle).RGB = RGB(255, 123, 99)