I am attempting to create a function that will return a specific shape, based on the known Name property assigned to the CustomLayout.Shapes.Placeholder
object. I can't use the shape .Name
because this is not known in advance, even when creating slides from template/layout.
The challenge seems to be how the custom layout is related to the actual slide. For instance, when I iterate the slide's .CustomLayout.Shapes.Placeholders
, I can easily identify the particular placeholder by it's .Name
property.
HOWEVER if I return this shape, it will be the custom layout placeholder, which affects ALL slides on this layout (e.g., if I add text to this placeholder, it updates all slides using this layout!). Obviously this is undesirable!
If instead, I index the collection, and attempt to return the shape at that index position, from the slide's .Shapes.Placeholders
, it appears that they are not maintaining the same index, i.e., .Shapes.Placeholders(i) <> .CustomLayout.Shapes.Placholders(i)
Attempted workaround:
Thought I might be able to manipulate the custom layout to add a Tag
to the shapes. I tried, and it fails for the same reasons (i.e., the CustomLayout.Shape is somehow not the "same" shape as the Slide.Shape...). In any case, I'm hoping to avoid a "workaround" in favor of a more proper way to do this, if such a thing exists.
This is the function I have so far:
Function GetShapeByPlaceholderName(sName As String, sld As Slide) As Object
Dim plchldrs As Placeholders
Dim shp As Shape
Dim ret As Shape
Dim i As Long
For Each shp In sld.CustomLayout.Shapes.Placeholders
i = i + 1
If shp.Name = sName Then
'####
' This can easily identify the CustomLayout.Shapes.PLACEHOLDER
'
' But I need to return the SHAPE in the Slide.Shapes collection
'####
'###
Set ret = shp 'This will return the CustomLayout.Placeholder, which affects ALL slides
'###
'Set ret = sld.Shapes.Placeholders(i) 'the index of the Shapes.Placeholders is NOT the same
'###
'Set ret = sld.Shapes.Placeholders.FindByName(sName) 'This returns an error/specified shape name does not exist
'###
'Set ret = sld.Shapes.Placeholders.FindByName(i) 'This observes same failure that the index of the collections is not the same
Exit For
End If
Next
Set GetShapeByPlaceholderName = ret
End Function