This PowerPoint VBA macro removes all the text-boxes from an active slide.
Macro Example
Sub RemoveTextboxes() Dim shp As Shape For Each shp In ActiveWindow.Selection.SlideRange.Shapes If shp.Type = msoTextBox Then shp.Delete End If Next shp End Sub
Description
Variable Declaration
Sub... Dim shp As Shape
The 3rd line declares an object variable named shp that refers to a Shape object.
The Shape object represents a placeholder, shape, freeform, OLE object or picture.
Starts Looping Through All Shapes
Sub... Dim shp As Shape For Each shp In ActiveWindow.Selection.SlideRange.Shapes
The 5th line starts to loop through all the elements (Shape) of a collection (Shapes). I will explain about the object model hierarchy:ActiveWindow.Selection.SlideRange.Shapes .
[Application.]ActiveWindow
For Each shp In ActiveWindow...
The Application.ActiveWindow property returns the DocumentWindow object that represents an active document window.
The ActiveWindow property is a member of the PowerPoint.Global class, so we can omit the Application property.
ActiveWindow.Selection [DocumentWindow.Selection]
For Each shp In ActiveWindow.Selection...
The ActiveWindow.Selection (DocumentWindow.Selection property) returns the Selection object that represents the selection in the document window.
Selection.SlideRange
For Each shp In ActiveWindow.Selection.SlideRange...
The Selection.SlideRange property returns the SlideRange object that represents a range of selected slides.
SlideRange.Shapes
For Each shp In ActiveWindow.Selection.SlideRange.Shapes
Finally, the SlideRange.Shapes property returns a Shapes collection object that represents all the shapes that have been placed on a slide.
Checking the Shape Type
Sub... Dim shp As Shape For Each shp In ActiveWindow.Selection.SlideRange.Shapes If shp.Type = msoTextBox Then
The 7th line checks whether the shape is a text-box.
Shape.Type
The Shape.Type property returns a MsoShapeType value that represents the shape type.
If the shape is a text-box then the Shape.Type property returns a const:msoTextBox .
Deleting the Shape
Sub... Dim shp As Shape For Each shp In ActiveWindow.Selection.SlideRange.Shapes If shp.Type = msoTextBox Then shp.Delete
The 8th line deletes the shape by the Shape.Delete method.
Loops Back
Sub... Dim shp As Shape For Each shp In ActiveWindow.Selection.SlideRange.Shapes If shp.Type = msoTextBox Then shp.Delete End If Next shp
The 11th line loops back to evaluate the next shape.
After every shape is evaluated, this macro ends.
Sub RemoveTextboxes() Dim shp As Shape For Each shp In ActiveWindow.Selection.SlideRange.Shapes If shp.Type = msoTextBox Then shp.Delete End If Next shp End Sub
Properties
http://www.relief.jp/itnote/archives/powerpoint-vba-remove-textboxes.php
Apply to
- PowerPoint 2013
- PowerPoint 2010
- PowerPoint 2007