PDA

View Full Version : How to access shapes with same name?



prabhafriend
12-19-2014, 06:45 AM
Hi,
I am Prabhakaran - a VBA Developer doing automation for more than five years in excel and Access, but very new to the powerpoint Object model. Currently doing an Automation in Powerpoint where in one slide there are two shapes having the exact samename (Content Placeholder 8). How to access them individually through code? And I have one more doubt: What is the difference between a table and a Content Placeholder? Acutally here in this presentation template I am seeing only tables named as Content Placeholder 8. Why its looking like a table but having a different name? Work at stake. Kindly help.
Regards,
Prabhakaran

SamT
12-19-2014, 10:28 AM
No. It is impossible to have two Shapes on one Slide with the same Name.

Select each "Shape" on the slide and discover it's Type. Type 1 = Slide; Type 2 = Shape; Type 3 = Text
Then discover the "Shape's" Parent Name and Type.


Sub WatchX()
Dim X

With Selection
X = .Type
X = .Name
With .Parent
X = .Type
x = .Name
End With
With Parent.Parent
'Continue
End With
End With
End Sub

A Table is an Object and "Content Placeholder (n)" is a name that is automatically assigned when certain objects are added. The same as new Worksheets in Excel are named "Sheet(n)". You are probably seeing Tables named "Content Placeholder (n)"

John Wilson
12-19-2014, 11:47 AM
It's not impossible to have shapes with the same name in PPT. (Not clever of MSFT but easy to achieve.)
Two placeholders with the same name it not easy to achieve though. How did you do this. However it's going to cause you pain.

SamT
12-19-2014, 12:26 PM
Please clarify for me; Is it possible to have two Shapes with the same Name in the same Slide? If so, How?

I have very little experience with PPT and all that with 2002 and 97.

John Wilson
12-20-2014, 04:17 AM
It is Sam (not clever though) You can rename the shapes in the selection pane to have the same name (people don't usually do this) OR rename one shape say to myShape and then copy and paste. The new shape will also be called myShape I think this only works after 2007 but not sure. It should be impossible but it isn't!

If you access and modify the shape with code only the first shape in the zorder will be affected.

SamT
12-20-2014, 02:34 PM
thanks.

Can you help the OP? I've just been muddling along.

Paul_Hossler
12-20-2014, 04:31 PM
Very hard coded way to tell two ContentPlaceHolders with the same name apart (the left one and the right one)

No error checking AT ALL

John's taught me a lot about the PP object model, but I still wish PP had an Excel quality macro recorder

Also, while the .Name properties can be the same, the .Id properties are still different



Option Explicit
Sub test()
Dim oPresentation As Presentation
Dim oSlide As Slide
Dim oShape As Shape
Dim oContentLeft As Shape, oContentRight As Shape

Set oPresentation = ActivePresentation
Set oSlide = oPresentation.Slides(2)

For Each oShape In oSlide.Shapes
With oShape
If .Name = "Content Placeholder 8" Then
If oContentLeft Is Nothing And oContentRight Is Nothing Then
Set oContentLeft = oShape
Else
Set oContentRight = oShape
End If
End If
End With
Next

If oContentLeft.Left > oContentRight.Left Then
Set oShape = oContentLeft
Set oContentLeft = oContentRight
Set oContentRight = oShape
End If


MsgBox "Left one = " & oContentLeft.Id
MsgBox "Right one = " & oContentRight.Id


End Sub



Once you have the 2 shapes Set, then you can test or do things

Look at the attached file if you want, but save it and just rename it to remove the .zip part since I can't seem to upload .PPTM files

Paul_Hossler
12-20-2014, 04:45 PM
The other approach is to open the slide masters on the template and rename them so you don't need to worry about the same names

All presentation created using your revised template will have your names

John Wilson
12-21-2014, 02:45 AM
Paul's right you need to rename but also work out HOW they have the same name.Usually this involves copy and pasting placeholders which is always a bad idea! Any quick fix is going to give future pain!

In any case placeholders on slides do not inherit the name from the master and it is pretty difficult to link a slide placeholder to it's parent. The time to rename on a slide is as the slide is created when the placeholders will share position with the masters.

Paul_Hossler
12-21-2014, 09:39 AM
Acutally here in this presentation template I am seeing only tables named as Content Placeholder 8. Why its looking like a table but having a different name? Work at stake. Kindly help.
Regards,
Prabhakaran


Another question ... the 'template' ...

a. Is it literally a .POTX or .POTM and in the Microsoft\Templates folder, (similar to .XLST or .XLTM) OR

b. Is it 'company standard' .PPTX or .PPTM that is copied and saved with a new name? (similar to .XLSX or .XLSM)

If it's a). then FileNew will create s new presentation (either .PPTX or .PPTM) so you'd want to fix the names there

If it's b). then I'd investigate creating a true template (a.)





but also work out HOW they have the same name.Usually this involves copy and pasting placeholders which is always a bad idea!


For sure, but Control-C/Control-V will copy a Content Place Holder if it's not empty. BUT Control-Click-Drag will create a copy of the empty one. In both cases the names are the same

Using the Selection Pane, it's easy to give them meaningful names ('List of Pros' and 'List of Cons', etc.). Same for other shapes, so instead of 'Picture 8' you could call the shape 'Company Logo'

John Wilson
12-21-2014, 11:41 AM
Ctrl C/V copies a placeholder on the master / layout and the name will be the same but on the slide in normal view they will get (should get) new different names. If you copy paste on the normal slide the name will duplicate but the pasted shape is not really a placeholder and will not really follow the master. Whatever it's a bad idea. Oh and if it's not a potx/m then as Paul says it should be.