我正在尝试创建一个函数,根据CustomLayout.Shapes.Placeholder
对象分配的已知名称属性返回特定形状。但是,我无法使用.Name
属性,因为这在预先不知道时无法使用,即使从模板/布局创建幻灯片。
挑战似乎在于自定义布局与实际幻灯片的关系。例如,当我迭代幻灯片的.CustomLayout.Shapes.Placeholders
时,我可以通过它的.Name
属性轻松地识别特定的占位符。
然而,如果我返回this形状,它将成为自定义布局占位符,这会影响此布局上的所有幻灯片(例如,如果我向这个占位符添加文本,它会更新使用此布局的所有幻灯片!)。显然,这是不可取的!
相反,如果我从幻灯片的.Shapes.Placeholders
中索引集合,并尝试返回该索引位置处的形状,则似乎它们未维护相同的索引,即 .Shapes.Placeholders(i) <> .CustomLayout.Shapes.Placholders(i)
尝试的解决方法:
我认为我可以操纵自定义布局以向形状添加Tag
。我尝试了一下,但由于相同的原因失败了(即,CustomLayout.Shape与Slide.Shape不是“同一个”形状...)。无论如何,如果存在这样的事情,我希望避免“解决方法”,而更愿意采用更适当的方法。
到目前为止,这就是我拥有的函数:
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