Muokkaa

Jaa


Slides.Range method (PowerPoint)

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

Syntax

expression.Range (Index)

expression A variable that represents a Slides object.

Parameters

Name Required/Optional Data type Description
Index Optional Variant The individual slides that are to be included in the range. Can be an Integer that specifies the index number of the slide, a String that specifies the name of the 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.

Return value

SlideRange

Remarks

Although you can use the Range method to return any number of shapes or slides, it is 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.

Dim myArray() As Variant, myRange As Object myArray = Array("Oval 4", "Rectangle 5") Set myRange = ActivePresentation.Slides(1).Shapes.Range(myArray)

Example

This example sets the title color for slides one and three.

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.

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)

See also

Slides Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.