Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA PowerPoint - Creating & Naming Table

Status
Not open for further replies.

icu222much

Technical User
Mar 12, 2007
26
CA
I am wondering how I am able to give my table a name after/while I am creating a table?

I have an existing powerpoint slide with several objects (mainly textboxes and simple shapes) in it. I would like to create a table with VBA, add an undetermined number of rows, and populate the table with data. When I run my code (see below) I get an error. I believe the problem is because I am not refering to the proper shape when trying to add rows/data to the table.

Here is the code I have so far. When I run it, I get the error "Shape (unknown member): Invalid request. This shape does not have a table".



Call ActivePresentation.Slides(1).Shapes.AddTable(lRows, lCols, sTLeft, sTTop, sTWidth, sTHeight)

ActivePresentation.Slides(1).Shapes(1).Table.Rows.Add

With ActivePresentation.Slides(3).Shapes(1).Table
.Cell(1, 1).Shape.TextFrame.TextRange.text = "A"
.Cell(1, 2).Shape.TextFrame.TextRange.text = "B"
.Cell(1, 3).Shape.TextFrame.TextRange.text = "C"
End With
 



Hi,

Just guessing...
Code:
ActivePresentation.Slides(1).Shapes.AddTable(lRows, lCols, sTLeft, sTTop, sTWidth, sTHeight)

ActivePresentation.Slides(1).Shapes([b]ActivePresentation.Slides(1).Shapes.count[/b]).Table.Rows.Add


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
The return value of 'Shapes.AddTable' is the new shape which contains the table, so just set it to a variable and use that variable:


Dim oShape As Shape

Set oShape = ActivePresentation.Slides(1).Shapes.AddTable(lRows, lCols, sTLeft, sTTop, sTWidth, sTHeight)

oShape.Table.Rows.Add

With oShape.Table
.Cell(1, 1).Shape.TextFrame.TextRange.Text = "A"
.Cell(1, 2).Shape.TextFrame.TextRange.Text = "B"
.Cell(1, 3).Shape.TextFrame.TextRange.Text = "C"
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top