如何在PowerPoint中判断幻灯片版式占位符是否全部被使用?
如果未使用某个版式占位符,可以防止添加图片时自动使用该占位符吗?
如何在PowerPoint中判断幻灯片版式占位符是否全部被使用?
如果未使用某个版式占位符,可以防止添加图片时自动使用该占位符吗?
if (selectedSlide.Shapes.Placeholders[i].PlaceholderFormat.ContainedType != Microsoft.Office.Core.MsoShapeType.msoAutoShape)
如果占位符中没有放置任何内容,则该占位符的 ContainedType 为 msoAutoShape。例如,在向占位符插入图像时,类型会更改为该项目的类型,即 msoPicture。
Office 会自动将项目添加到第一个可用的占位符(在主文件中首先添加),或者对于图像,会优先考虑 ppPlaceholderPicture。
您需要循环遍历幻灯片上的所有占位符,确定每个占位符的类型,然后检查它是否填充了预期的格式。有18个PpPlaceholderType
,因此您需要设置它们所有,但以下是一个示例,可以用来检查占位符是否正在使用。
Sub CheckPlaceholders()
Dim ap As Presentation: Set ap = ActivePresentation
Dim sl As Slide: Set sl = ap.Slides(2)
Dim shs As Shapes: Set shs = sl.Shapes
Dim ph As Placeholders: Set ph = shs.Placeholders
Dim p As Shape
For Each p In ph
Select Case p.Type
Case PpPlaceholderType.ppPlaceholderHeader
If p.TextFrame.HasText Then
Debug.Print "This Placeholder is in use"
End If
Case PpPlaceholderType.ppPlaceholderChart
If p.HasChart Then
Debug.Print "This Placeholder is in use"
End If
End Select
Next
End Sub
Sub AddPicture()
Dim pic As String
pic = "C:\Users\Me\Desktop\beigeplum.jpg"
Dim ap As Presentation: Set ap = ActivePresentation
Dim sl As Slide: Set sl = ap.Slides(1)
Dim sh As Shape
Do
Set sh = sl.Shapes.AddPicture(pic, msoFalse, msoTrue, 1, 1)
sh.Tags.Add "MYPICTURE", 0
Loop Until sh.Type <> 14
Dim p As Shape
For Each p In sl.Shapes
If p.Type = 14 Then
If p.Tags.count > 0 Then
If p.Tags.Name(1) = "MYPICTURE" Then
p.Delete
End If
End If
End If
Next
End Sub
Delete()
删除shape
。因此,首先将它们添加到一个List
中,然后再进行Delete()
操作。 - Sam007.HasBlah
属性吗?(有几个)。 - 我们还需要检查其他没有自己的.HasBlah
属性的东西吗? - BrainSlugs83