PowerPoint Macro: Removing Alternative Texts of Shapes on an Active Slide

This PowerPoint VBA macro removes alternative texts of all the shapes on an active slide.

Macro Example

Sub RemoveAlternativeText_ActiveSlide()

  Dim shp As Shape

  For Each shp In ActiveWindow.Selection.SlideRange.Shapes 
    With shp
      .AlternativeText = ""
      .Title = ""
    End With
  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.

obj-PowerPoint-Shape

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.

obj-PowerPoint-Application-ActiveWindow

The ActiveWindow property is a member of the PowerPoint.Global class, so we can omit the Application property.

obj-PowerPoint-Global-ActiveWindow

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.

obj-PowerPoint-DocumentWindow-Selection

Selection.SlideRange

  For Each shp In ActiveWindow.Selection.SlideRange...

The Selection.SlideRange property returns the SlideRange object that represents a range of selected slides.

obj-PowerPoint-Selection-SlideRange

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.

obj-PowerPoint-SlideRange-Shapes

Starts the With structure

Sub...

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    With shp

The 6th line starts the With…End With statement.
This statement tells PowerPoint that any action apply to the shp (Shape object).

Removing the Alternative Text

Sub...

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    With shp
      .AlternativeText = ""

The 7th line removes the alternative text.

Shape.AlternativeText

The shp.AlternativeText (Shape.AlternativeText property) returns or sets the alternative text associated with the Shape object in a Web presentation.

obj-PowerPoint-Shape-AlternativeText

Removing the Title Text

Sub...

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    With shp
      .AlternativeText = ""
      .Title = ""

The 8th line removes the title text.

Shape.Title

The shp.Title (Shape.Title property) returns or sets the title associated with the Shape object in a Web presentation.

obj-PowerPoint-Shape-Title

Loops Back

Sub...

  Dim shp As Shape

  For Each shp In ActiveWindow.Selection.SlideRange.Shapes 
    With shp
      .AlternativeText = ""
      .Title = ""
    End With
  Next shp

The 10th line loops back to evaluate the next shape.

After every shape is evaluated, this macro ends.

Sub RemoveAlternativeText_ActiveSlide()

  Dim shp As Shape

  For Each shp In ActiveWindow.Selection.SlideRange.Shapes 
    With shp
      .AlternativeText = ""
      .Title = ""
    End With
  Next shp

End Sub

Properties

http://www.relief.jp/itnote/archives/powerpoint-macro-remove-alternative-text.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007