Working with Table Presentation Properties in PowerPoint 2010
Working with Tables in Microsoft Office 2010: Learn how to work with the visual properties of a table in Microsoft PowerPoint 2010.
Applies to: Excel 2010 | Office 2010 | PowerPoint 2010 | VBA | Word 2010
In this article
Add a Standard Module to a PowerPoint Presentation
Add the Code to the Visual Basic Editor
Test the Solution
Next Steps
Published: June 2011
Provided by: Frank Rice, Microsoft Corporation
Changing the styles of the various parts of a table such as the horizontal and vertical banding of its rows, and its column properties, enhances the display of a table. In this topic, you programmatically add a table to a Microsoft PowerPoint 2010 presentation and then manipulate some of its visual properties. To complete this task, you must do the following:
Add a Standard Module to a PowerPoint Presentation
Add the Code to the Visual Basic Editor
Test the Solution
Add a Standard Module to a PowerPoint Presentation
In this task, you open a PowerPoint 2010 presentation, open the Visual Basic Editor, and then insert a standard module.
To add a standard module to a PowerPoint presentation
Start PowerPoint 2010.
On the Developer tab, click Visual Basic. This opens the Visual Basic Editor.
Note
If you do not see the Developer tab in PowerPoint 2010, click the File tab, and then click Options. In the categories pane, click Popular, select Show Developer tab in the Ribbon, and then click OK.
On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.
Add the Code to the Visual Basic Editor
In this task, you add programming code to the Visual Basic Editor.
To add code to the Visual Basic Editor
In the Projects pane, click Module1.
Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.
Sub TableProperties() Dim pres As Presentation Set pres = ActivePresentation Dim sld As Slide Set sld = pres.Slides.Add(2, ppLayoutTable) sld.Select Dim tbl As Table Set tbl = sld.Shapes.AddTable(4, 4).Table FillTable tbl ' Variables to maintain the state: Dim savedFirstRow As Boolean Dim savedFirstCol As Boolean Dim savedHorizBanding As Boolean Dim savedLastCol As Boolean Dim savedLastRow As Boolean Dim savedVertBanding As Boolean ' Store the current state: savedFirstRow = tbl.FirstRow savedFirstCol = tbl.FirstCol savedHorizBanding = tbl.HorizBanding savedLastCol = tbl.LastCol savedLastRow = tbl.LastRow savedVertBanding = tbl.VertBanding ' Alter all settings: tbl.HorizBanding = Not savedHorizBanding tbl.VertBanding = Not savedVertBanding tbl.FirstRow = Not savedFirstRow tbl.FirstCol = Not savedFirstCol tbl.LastCol = Not savedLastCol tbl.LastRow = Not savedLastRow ' Scale the table to half size: tbl.ScaleProportionally 0.5 ' Put it back the way it was (twice as big as it is currently): tbl.ScaleProportionally 2 ' Put things back the way they were: tbl.HorizBanding = savedHorizBanding tbl.VertBanding = savedVertBanding tbl.FirstRow = savedFirstRow tbl.FirstCol = savedFirstCol tbl.LastCol = savedLastCol tbl.LastRow = savedLastRow End Sub Sub FillTable(tbl As Table) ' Fill a table with sample data. Dim row As Integer Dim col As Integer For col = 1 To tbl.Columns.Count tbl.Cell(1, col).Shape.TextFrame.TextRange.Text = "Heading " & col Next col For row = 2 To tbl.Rows.Count For col = 1 To tbl.Columns.Count tbl.Cell(row, col).Shape.TextFrame.TextRange.Text = "Cell " & row & ", " & col Next col Next row End Sub
Test the Solution
In this task, you step through the code. The best way to see the code in action is to place the Visual Basic Editor and the PowerPoint screen side-by-side.
To step through the code
Drag the Visual Basic Editor to the right side of the screen.
Next, drag the PowerPoint screen to the left side of the screen and adjust both screens until you can see clearly.
Place your cursor in the TableProperties module, press F8 to get started debugging, and then press Shift+F8 to step through the code line-by-line (and bypass external procedures) and watch the code behavior.