KB0073:如何使用 VBA 判断某个形状是否被 thinkcell 使用?

  1. Home
  2. 资源
  3. 知识库
  4. KB0073

thinkcell 遇到的每个形状都会被标记一个标签。除了 PowerPoint 形状之外,thinkcell 还可能在幻灯片、幻灯片母版或自定义版式上放置一个特殊形状(ActiveDocument 容器)。此 ActiveDocument 容器不可见,并包含有关 thinkcell 对象的特殊信息。在 PowerPoint 对象模型中,每个 PowerPoint.Shape 对象都有一个 Tags 集合。thinkcell 会设置特殊标签 thinkcellShapeDoNotDelete,以帮助识别形状。对于 ActiveDocument 容器,该特殊标签的值设置为 thinkcellActiveDocDoNotDelete;对于所有其他由 thinkcell 控制的形状,其值以 t 开头。

示例:如何检查 thinkcell 形状?

以下 VBA 函数演示如何使用特殊标签对给定的 PowerPoint.Shape 对象进行分类:

Sub CheckShape(oShape As PowerPoint.Shape)
    Dim str As String
    str = oShape.Tags.Item(Name:="thinkcellShapeDoNotDelete")
    If (str = "" Or Left$(str, 1) <> "t") Then
        MsgBox "PowerPoint 形状"
    Else
        If str = "thinkcellActiveDocDoNotDelete" Then
            MsgBox "thinkcell ActiveDocument"
        Else
            MsgBox "thinkcell 形状"
        End If
    End If
End Sub

您可以使用此函数识别当前幻灯片上的所有形状:

Sub Test()
    Dim oShape As PowerPoint.Shape
    For Each oShape In ActiveWindow.View.Slide.Shapes
        Call CheckShape(oShape)
    Next oShape
End Sub

请注意,每当您复制形状时,也会同时复制该形状的标签集合,例如复制并粘贴 thinkcell 图表时。 CheckShape 会对所有曾经属于 thinkcell 图表的形状报告 thinkcell shape,即使该形状已被复制并粘贴到另一个演示文稿中。

您可能还想阅读 KB0107:如何在 VBA 代码中复制粘贴 thinkcell 图表?