Selection object (PowerPoint)
Represents the selection in the specified document window. The Selection object is deleted whenever you change slides in an active slide view (the Type property will return ppSelectionNone).
Example
Use the Selection property to return the Selection object. The following example places a copy of the selection in the active window on the Clipboard.
ActiveWindow.Selection.Copy
Use the ShapeRange, SlideRange, or TextRange property to return a range of shapes, slides, or text from the selection.
The following example sets the fill foreground color for the selected shapes in window two, assuming that there's at least one shape selected, and assuming that all selected shapes have a fill whose forecolor can be set.
With Windows(2).Selection.ShapeRange.Fill
.Visible = True
.ForeColor.RGB = RGB(255, 0, 255)
End With
The following example sets the text in the first selected shape in window two if that shape contains a text frame.
With Windows(2).Selection.ShapeRange(1)
If .HasTextFrame Then
.TextFrame.TextRange = "Current Choice"
End If
End With
The following example cuts the selected text in the active window and places it on the Clipboard.
ActiveWindow.Selection.TextRange.Cut
The following example duplicates all the slides in the selection (if you are in slide view, this duplicates the current slide).
ActiveWindow.Selection.SlideRange.Duplicate
If you don't have an object of the appropriate type selected when you use one of these properties (for instance, if you use the ShapeRange property when there are no shapes selected), an error occurs. Use the Type property to determine what kind of object or objects are selected. The following example checks to see whether the selection contains slides. If the selection does contain slides, the example sets the background for the first slide in the selection.
With Windows(2).Selection
If .Type = ppSelectionSlides Then
With .SlideRange(1)
.FollowMasterBackground = False
.Background.Fill.PresetGradient _
msoGradientHorizontal, 1, msoGradientLateSunset
End With
End If
End With
Methods
Name |
---|
Copy |
Cut |
Delete |
Unselect |
Properties
Name |
---|
Application |
ChildShapeRange |
HasChildShapeRange |
Parent |
ShapeRange |
SlideRange |
TextRange |
TextRange2 |
Type |
See also
PowerPoint Object Model Reference
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.