PowerPoint VBA: Adding Table on Active Slide

This PowerPoint VBA macro adds a table on an active slide.

Macro Example

Sub AddTable()

  With ActiveWindow.Selection.SlideRange
    .Shapes.AddTable _
      NumRows:=5, _
      NumColumns:=3  
  End With

End Sub

Description

[Application.]ActiveWindow

Sub...

  With 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)

Sub...

  With 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

Sub...

  With ActiveWindow.Selection.SlideRange

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

obj-PowerPoint-Selection-SlideRange

In this macro it represents an active slide.

SlideRange.Shapes

Sub AddTable()

  With ActiveWindow.Selection.SlideRange
    .Shapes...

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

Shapes.AddTable

Sub AddTable()

  With ActiveWindow.Selection.SlideRange
    .Shapes.AddTable _
      NumRows:=5, _
      NumColumns:=3  

The Shapes.AddTable method adds a table shape to a slide. The table has five rows and three columns.

obj-PowerPoint-Shapes-AddTable

Sub AddTable()

  With ActiveWindow.Selection.SlideRange
    .Shapes.AddTable _
      NumRows:=5, _
      NumColumns:=3  
  End With

End Sub

Properties

http://www.relief.jp/itnote/archives/powerpoint-vba-add-table.php

Apply to

  • PowerPoint 2013
  • PowerPoint 2010
  • PowerPoint 2007