VBA Help -- Referencing Table

W

wrldruler

I am exporting data from Access to PowerPoint and almost have it
working.

First I coded using the "names" of the shapes

With PPSlide.Shapes.Item("Text Box 301").TextFrame.TextRange

This worked fine until I wanted to have the database create duplicate
slides. Evidently the names change when a slide is duplicated, thus
breaking my code.

So I changed the code to reference by shape index:

With PPSlide.Shapes(14).TextFrame.TextRange

This works fine for all my textboxes. But I can't get the syntax
correct for tables.

My old code by "name" is:

With PPSlide.Shapes.Item("Group 549").Table

But I can't figure out what Index the table or group is. How do i
indetify the shape index of a table, and what is the correct syntax
for referencing?

Thanks,

Chris
 
T

T Lavedas

I am exporting data from Access to PowerPoint and almost have it
working.

First I coded using the "names" of the shapes

With PPSlide.Shapes.Item("Text Box 301").TextFrame.TextRange

This worked fine until I wanted to have the database create duplicate
slides. Evidently the names change when a slide is duplicated, thus
breaking my code.

So I changed the code to reference by shape index:

With PPSlide.Shapes(14).TextFrame.TextRange

This works fine for all my textboxes. But I can't get the syntax
correct for tables.

My old code by "name" is:

With PPSlide.Shapes.Item("Group 549").Table

But I can't figure out what Index the table or group is. How do i
indetify the shape index of a table, and what is the correct syntax
for referencing?

Thanks,

Chris

I agree that this is very frustrating. I understand v2007 has a
viewer that shows all of the names and allows renaming them, though
that may not help in automating your process.

The only workaround I have found is to sort through all of the shapes
on a slide until a partial match can be found in the Name property of
each shape. For example, if there is only one 'Group' shape on the
slide it's name can be determined by a FOR each shape in Shapes
loop ...

' For example ...

Sub Macro1()
'
' Macro recorded 6/18/2008 by Tom Lavedas
'

With ActiveWindow.Selection.SlideRange
For Each oShape In .Shapes
if Instr(oShape.Name, "Group") then
s = s & oShape.Name & " *" &vbCrLf
else
s = s & oShape.Name & vbCrLf
end if
Next
End With
MsgBox s
End Sub

This works best if you need to process a particular class of shape or
if there is just one such item on each slide. If you need to find a
particular one, I don't know an easy way to figure that our, unless
there is some other peculiar property that will tell it apart from the
others - say the one with the highest (lowest) number part in its
name. That can be parsed off using the Split() function ...

aName = Split(oShape.Name)
sTextPart = aName(0)
nNumberPart = aName(1)

Note that the Name property is read/write, so your code can change it
once it is located, but that name still needs to be unique.

BTW, I didn't actually produce the code by recording it - I just used
the recorder to get the right syntax for the selection of a shape and
used it as the foundation of the little example.

HTH,

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
W

wrldruler

Thanks for the response Tom.

I currently use a For statement to help identify the object names
during dvelopment. If you use oShape.Type, you can look for your
desired shapes. Type = 19 is Group.

But your post gave me an idea. I never considered running the For code
during execution to identify the changing Group name. That might do
the trick.

Thanks,
Chris
 
W

wrldruler

Actually, Type = 19 is a Table.  Type = 6 is a Group.

Thanks for catching that -- I didn't have my code in front of me :)

I am good now. I do have two different tables that need to be
identified, but thankfully they are not the same height, so I was able
to iterate through all the shapes, pull out the two tables, look at
the height, and then pull the name.

Dim Table_NS_Name As String
Dim Table_Risk_Name As String

For Each ppShape In PPSlide.Shapes

If ppShape.Type = 19 Then

If ppShape.Height = 88.125 Then
Table_NS_Name = ppShape.Name
Else
Table_Risk_Name = ppShape.Name
End If


End If
Next

With PPSlide.Shapes(Table_NS_Name).Table
.......


No. Life was easier when my old boss had me automate to Excel.
PowerPoint automation is a lot harder than it needs to be.

Thanks everyone.
 
T

T Lavedas

Another approach would be to name the table or better yet, Tag it.

Working with Tags (and a bit about Functions)http://www.pptfaq.com/FAQ00815.htm






-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

Humm, but doesn't that require the determination that the name/tag is
being applied to the correct shape? Fine, when done to a manually
selected shape, but not when an automated process has created the
shape that was arbitrarily named by the application. Or am I missing
something?

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
W

wrldruler

If they're, in effect, part of a template PPT and are being populated with data via
automation, it'd be easy to tag them in advance so that the automated solution
could find them at need.

Agree. I was doing this first, and you are correct. I could determine
the name ahead of time, and reference without a problem.
Or if the automated solution is creating the tables in the first place, it could
easily tag them as well so it can find them later.

Agree. If I was using code to generate the table, I could tag it at
the time of creation.
But yep, if this is all happening after the fact and the code has to first work out
which table is which before working on it, then tagging isn't going to help much.

There's my problem. Slide 1 of my file is my template. I then run
<<ppFile.Slides(1).Duplicate>>, to create a second slide (and a third,
fourth....) When I run the duplicate, it forces all the shapes on
Slide 2 to take a new name.

I have been able to reference the textboxes by their Index on the
screen -- all shapes keep the same index when a slide is duplicated
<<With PPSlide.Shapes(14).TextFrame.TextRange>>

But I couldn't figure out how to reference a table by its index
number. I had to work around it by iterating through the shapes,
looking for a specific height that doesn't change, and then locking
into the new name.

Thanks
 

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