Function Reference

_PPT_ShapeRangeSet

Creates a ShapeRange object with one or multiple Shapes from one or multiple Slides.

#Include <PowerPoint.au3>
_PPT_ShapeRangeSet($oPresentation[, $vSlides = 0[, $vShapes = 0]])

 

Parameters

$oPresentation Presentation object.
$vSlides [optional] Slide or Slides to create the SlideRange object from (default = 0 = all Slides).
$vShapes [optional] Shape or Shapes to create the ShapeRange object from (default = 0 = all Shapes). Please see Remarks.

 

Return Value

Success: ShapeRange object.
Failure: 0 and sets @error.
    1 - $oPresentation is not an object or not a presentation object
    2 - $vSlides is an object but not a Slide or SlideRange object
    3 - Error occurred creating the SlideRange from $vSlides. @extended is set to the error code returned by _PPT_SlideRangeSet
    4 - Error occurred creating the SlideRange from $vSlides. @extended is set to the COM error code returned by the Range method
    5 - $vShapes is an object but not a ShapeRange object
    6 - Error occurred creating the ShapeRange from $vShapes. @extended is set to the COM error code returned by the Range method
    7 - $vShapes is an object but not a Shape or ShapeRange object
    8 - $vShapes has invalid format

 

Remarks

The ShapeRange parameter $vShapes can be defined using one of the following formats:
* collection of individual Shapes:
- ShapeRange object
- Index number of the first and last Shape separated by a hyphen e.g. 1-3 or 1-* (* represents the last Shape)
- Index number: -1 (ShapeRange consists of all selected Shapes)
- Zero based array holding the index numbers or names of the Shapes
* collection of all Shapes:
- Shapes object
- Index number: 0 (ShapeRange consists of all Shapes)
* single Shape:
- Shape object
- Index number
- Shape name

Just as you can work with several slides at the same time in the user interface by selecting them and applying a command,
you can work with several slides at the same time programmatically by constructing a SlideRange collection and applying properties
or methods to it. And just as some commands in the user interface that work on single slides aren't valid when multiple slides are
selected, some properties and methods that work on a Slide object or on a SlideRange collection that contains only one slide will
fail if they're applied to a SlideRange collection that contains more than one slide.
In general, if you can't do something manually when more than one slide is selected (such as return the individual shapes on one
of the slides), you can't do it programmatically by using a SlideRange collection that contains more than one slide.
See: https://docs.microsoft.com/en-us/office/vba/api/powerpoint.SlideRange

 

Related

 

Example


#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=N
#include <Array.au3>
#include <PowerPoint.au3>
#include <MsgBoxConstants.au3>

; **********************************************************
; Create application object and open an example presentation
; **********************************************************
Global $sPresentation = @ScriptDir & "\Presentation1.pptx"
Global $oPPT = _PPT_Open()
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeRangeSet Example", "Error creating the PowerPoint application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Global $oPresentation = _PPT_PresentationOpen($oPPT, $sPresentation)
If @error Then
    MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeRangeSet Example", "Error opening presentation '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _PPT_Close($oPPT)
    Exit
EndIf

; *****************************************************************************
; Create a Shape Range
; *****************************************************************************
Global $oShapeRange
Global $aSlides[] = [1, 2]
Global $aShapes[] = [1, 2, 3]

MsgBox($MB_ICONQUESTION, "", "Select one or multiple shape(s)")
$oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), -1)
If @error Then Exit MsgBox($MB_ICONERROR, "PowerPoint UDF: _PPT_ShapeRangeSet Example 1", "Error creating a shape range for '" & $sPresentation & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
$oShapeRange.ShapeStyle = 10001
MsgBox($MB_ICONINFORMATION, "PowerPoint UDF: _PPT_ShapeRangeSet Example 1", "ShapeRange created")

; More examples
; $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), 0)                                            ; Slide 1 all shapes
; $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), $oPresentation.Slides(1).Shapes.Range(3))     ; Slide 1 shape 3 (ShapeRange)
; $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), $oPresentation.Slides(1).Shapes(3))           ; Slide 1 shape 3 (Shape)
; $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), $aShapes)                                     ; Slide 1 shapes defined in an array
; $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), "2-*")                                        ; Slide 1 shape 2 to the last
; $oShapeRange = _PPT_ShapeRangeSet($oPresentation, $oPresentation.Slides(1), "2-3")                                        ; Slide 1 shapes 2 and 3