【问题标题】:Accessing SmartArt shapes when the SmartArt is inside a Placeholder (PowerPoint 2007)当 SmartArt 位于占位符内时访问 SmartArt 形状 (PowerPoint 2007)
【发布时间】:2010-08-24 15:05:44
【问题描述】:

我需要浏览 PowerPoint 2007 中智能艺术的每个形状。 当shape.Type=msoSmartArt 时,我可以简单地浏览 shape.GroupItems 中的形状。

但是,当shape.Type == msoPlaceholder && shape.PlaceholderFormat.ContainedType==msoSmartArt 然后shape.GroupItems 为空。在这种情况下如何访问 Smart Art 形状?


我以前认为 VBA 和 C# VSTO 基本相同。

嗯 - 这里有区别。我在实际的 VBA 中尝试了 Otaku 的代码,它似乎确实有效(抱歉,Otaku 混淆了)。

但是,我的程序是在 C# VSTO 中,并且:

foreach (Shape slideShape in pres.Slides[1].Shapes)
{
  if (slideShape.Type != MsoShapeType.msoSmartArt &&   !(slideShape.Type == MsoShapeType.msoPlaceholder &&  slideShape.PlaceholderFormat.ContainedType==MsoShapeType.msoSmartArt))
 continue;

 GroupShapes shapes=slideShape.GroupItems;
 Debug.WriteLine(shapes.Count);
}

产生:shapes.Count=0(当形状类型为占位符,包含类型为 SmartArt 时)。

有什么想法吗?

【问题讨论】:

  • 不是真的......但我确实将答案标记为有用,因为它在 VB 中有效。

标签: vba vsto powerpoint


【解决方案1】:

使用GroupShapes,比如:

Sub GetSAfromPlaceholder()
    Dim ap As Presentation: Set ap = ActivePresentation
    Dim sl As Slide: Set sl = ap.Slides(2)
    Dim sh As Shape: Set sh = sl.Shapes(2)
    Dim gsh As GroupShapes: Set gsh = sh.GroupItems
    If sh.Type = msoPlaceholder Then
        If sh.PlaceholderFormat.ContainedType = msoSmartArt Then
        Debug.Print "SmartArt Shape Count: " & gsh.Count
          For i = 1 To gsh.Count
            If gsh(i).TextFrame.HasText Then
                Debug.Print gsh(i).TextFrame.TextRange.Text
            End If
            Next
        End If
    End If
End Sub

【讨论】:

  • 这似乎没有帮助。当: shape.Type == msoPlaceholder && shape.PlaceholderFormat.ContainedType==msoSmartArt 你得到空的 gsh。 (gshCount=0) 一种解决方法是复制 Smartart 并将其粘贴。粘贴的形状将包含所有实际形状的 GroupItems。但是,这种解决方法有点混乱。
  • 也许如果我能以某种方式从占位符中获取其包含的 SmartArt 形状,它可能会解决问题。有没有办法做到这一点?
  • 它非常适合我。 gshCount 总是大于 0。我所做的是在两个非标题占位符中创建了一个 Two Content 布局的空白幻灯片,我单击了 SmartArt 图标并插入了 SmartArt(每个中的类型不同)。我在一些节点中输入了一些文本。我已经更新了上面的代码来证明它是如何在我这边工作的(即它只有在sh.Type = msoPlaceholder sh.PlaceholderFormat.ContainedType = msoSmartArt 时才有效)。
【解决方案2】:

我使用的解决方法是复制 SmartArt 并将其粘贴回去。 粘贴的 SmartArt 现在在其 GroupItems 中具有所有形状。 处理完这些后,我删除了粘贴的形状。

【讨论】:

    猜你喜欢
    • 2015-01-14
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2015-01-16
    • 2011-07-11
    • 2015-05-11
    • 2015-10-06
    • 1970-01-01
    相关资源
    最近更新 更多