PowerPoint Macro: Turning Off the Autofit Settings for All Shapes on an Active Slide

This PowerPoint VBA macro turns off the auto-fit settings for all the shapes on an active slide.

Macro Example

Sub TurnOffAutoFitSettings_ActiveSlide()

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    shp.TextFrame.AutoSize = ppAutoSizeNone
  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

Turning Off the Auto-Fit settings

Sub...

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    shp.TextFrame.AutoSize = ppAutoSizeNone

The 6th line turns off the auto-fit setting of an each shape.

Shape.TextFrame

    shp.TextFrame...

The shp.TextFrame (Shape.TextFrame property) returns the TextFrame object that represents the text-frame in the Shape object.

obj-PowerPoint-Shape-TextFrame

TextFrame.AutoSize

    shp.TextFrame.AutoSize...

The TextFrame.AutoSize property returns or sets a value that indicates whether the size of the specified shape is changed automatically to fit text within its boundaries.

obj-PowerPoint-TextFrame-AutoSize

    shp.TextFrame.AutoSize = ppAutoSizeNone

By setting TextFrame.AutoSize property to ppAutoSizeNone, the auto-fit is set to do not auto-fit.

Loops Back

Sub...

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    shp.TextFrame.AutoSize = ppAutoSizeNone
  Next shp

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

After every shape is evaluated, this macro ends.

Sub TurnOffAutoFitSettings_ActiveSlide()

  Dim shp As Shape
 
  For Each shp In ActiveWindow.Selection.SlideRange.Shapes
    shp.TextFrame.AutoSize = ppAutoSizeNone
  Next shp

End Sub

Properties

http://www.relief.jp/itnote/archives/powerpoint-vba-auto-size-off.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007