Editing native PPT tables with VBA

R

Richard Smith

Greetings and thanks in advance.

Can anyone direct me to resources for editing native data tables in
PowerPoint via VBA? I've had success using embedded Excel tables in
PowerPoint but I have never been able to figure out how to get control of
individual elements of a data table in PowerPoint. I can identify and
control the table itself and even edit a cell in the table while recording a
macro and then viewing the results but the cells of the table don't seem to
be ordered in particularly logical ways that would give me confidence that
I'm editing the correct cell of the table. I'm a PhD mathematician and have
some experience identifying patterns but this one has me a bit befuddled.

Thanks again,

Richard.
 
R

Richard Smith

(I had meant to post this reply to the group but instead sent it to your
email address Shyam.)

Fantastic Shyam. That is exactly what I needed.
In retrospect, I can see that what was throwing me is that when rows are
added, the indexing assumes that the most recent row added is the last row,
even if it isn't the bottom row. Most all of the powerpoint tables that I
was trying to manipulate were inherited from presentations that I didn't
create and who knows how many times rows were added or deleted. Since I
didn't know that cells could be accessed via rows and columns (ala Excel), I
was trying to leverage the indexing (that's what would show up when
recording a macro, manipulating cells and reviewing the code) and it wasn't
making much sense.

Another oddity that I encountered is that if I name the table (via ppTools)
and then add a row, the name of the table seems to be destroyed (note that
I'm adding a row manually rather than via code) and revert to something like
"Group 60". Any thoughts on that phenomenon?

Thanks again,

Richard.
 
S

Steve Rindsberg

Another oddity that I encountered is that if I name the table (via ppTools)
and then add a row, the name of the table seems to be destroyed (note that
I'm adding a row manually rather than via code) and revert to something like
"Group 60". Any thoughts on that phenomenon?

I suspect it's because PPT treats a table as a special case of a Group shape.

While you can modify the shapes within a group, you can't add shapes or delete
them; the group is, in effect, a list of the shapes that comprise it, so
changing the list contents nullifies the group.

I'm guessing, then, that in order to add rows/columns (sets of shapes) to a
table, PPT has to save its name, ungroup it, modify it, regroup it and name it
back to the original name.

The fun part is this: the name it uses is the name it assigns when it creates
a shape or group. The .Name property that we can change via VBA is set to that
by default but isn't the same thing. And it disappears in any case when the
group is destroyed.

You can probably get around this easily enough by doing the same thing as PPT
but with the .Name property.

Dim sOriginalName as String
Set oSh = [your table]
sOriginalName = oSh.Name

' do stuff to the table
' get a reference to the newly regrouped table in oSh
oSh.Name = sOriginalName
 
R

Richard Smith

Worked like a charm. I hope that you guys get a lot of benefit from all the
free benefits that you provide to MS Office users.

Cheers,

Richard.

Steve Rindsberg said:
Another oddity that I encountered is that if I name the table (via
ppTools)
and then add a row, the name of the table seems to be destroyed (note
that
I'm adding a row manually rather than via code) and revert to something
like
"Group 60". Any thoughts on that phenomenon?

I suspect it's because PPT treats a table as a special case of a Group
shape.

While you can modify the shapes within a group, you can't add shapes or
delete
them; the group is, in effect, a list of the shapes that comprise it, so
changing the list contents nullifies the group.

I'm guessing, then, that in order to add rows/columns (sets of shapes) to
a
table, PPT has to save its name, ungroup it, modify it, regroup it and
name it
back to the original name.

The fun part is this: the name it uses is the name it assigns when it
creates
a shape or group. The .Name property that we can change via VBA is set to
that
by default but isn't the same thing. And it disappears in any case when
the
group is destroyed.

You can probably get around this easily enough by doing the same thing as
PPT
but with the .Name property.

Dim sOriginalName as String
Set oSh = [your table]
sOriginalName = oSh.Name

' do stuff to the table
' get a reference to the newly regrouped table in oSh
oSh.Name = sOriginalName
 
S

Steve Rindsberg

Worked like a charm. I hope that you guys get a lot of benefit from all the
free benefits that you provide to MS Office users.

I suppose we all do it for a different mix of reasons but we all enjoy it, or
we wouldn't be here.

And thoughtful "thankyou"s like yours ice the cake nicely. ;-)

Cheers,

Richard.

Steve Rindsberg said:
Another oddity that I encountered is that if I name the table (via
ppTools)
and then add a row, the name of the table seems to be destroyed (note
that
I'm adding a row manually rather than via code) and revert to something
like
"Group 60". Any thoughts on that phenomenon?

I suspect it's because PPT treats a table as a special case of a Group
shape.

While you can modify the shapes within a group, you can't add shapes or
delete
them; the group is, in effect, a list of the shapes that comprise it, so
changing the list contents nullifies the group.

I'm guessing, then, that in order to add rows/columns (sets of shapes) to
a
table, PPT has to save its name, ungroup it, modify it, regroup it and
name it
back to the original name.

The fun part is this: the name it uses is the name it assigns when it
creates
a shape or group. The .Name property that we can change via VBA is set to
that
by default but isn't the same thing. And it disappears in any case when
the
group is destroyed.

You can probably get around this easily enough by doing the same thing as
PPT
but with the .Name property.

Dim sOriginalName as String
Set oSh = [your table]
sOriginalName = oSh.Name

' do stuff to the table
' get a reference to the newly regrouped table in oSh
oSh.Name = sOriginalName
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top