所有幻灯片中的VBA取消组合所有PowerPoint形状

时间:2016-07-22 17:15:38

标签: vba macros powerpoint

我有一个宏,不幸的是跳过PowerPoint中所有分组的形状,其中文本需要规范化(硬回车用空格标记交换)。现在,我写了一个'准备'脚本,应该找到所有带有文本的形状并取消组合。由于某种原因,它无法正常工作。这应该是如此简单,但我不能让它工作。请帮忙!

Sub Ungroupallshapes()
    Dim osld As Slide
    Dim oshp As Shape
    For Each osld In ActivePresentation.Slides
        For Each oshp In osld.Shapes
            If oshp.Type = msoGroup Then
                If oshp.HasTextFrame Then
                    If oshp.TextFrame.HasText Then oshp.Ungroup
                    End If
                End If
        Next oshp
    Next osld
End Sub

谢谢!

2 个答案:

答案 0 :(得分:0)

群组没有TextFrame,因此您正在测试一些永远不会发生的事情。

If oshp.Type = msoGroup then oshp.Ungroup 

应该为简单的分组做到这一点。但是,取消组合会产生不必要的副作用(例如,吹走组形状上的任何动画)。而且通常不需要它。考虑:

Sub ChangeTheText()

    Dim oshp As Shape
    Dim oSld As Slide
    Dim x As Long

    For Each oSld In ActivePresentation.Slides
        For Each oshp In oSld.Shapes
            If oshp.HasTextFrame Then
                oshp.TextFrame.TextRange.Text = "Ha! Found you!"
            Else
                If oshp.Type = msoGroup Then
                    For x = 1 To oshp.GroupItems.Count
                        If oshp.GroupItems(x).HasTextFrame Then
                            oshp.GroupItems(x).TextFrame.TextRange.Text _
                                = "And you too, you slippery little devil!"
                        End If
                    Next
                End If
            End If
        Next
    Next
End Sub

这仍然会让你知道群组中的群体可能存在的问题(群组内(群组内))等等。有很多方法可以解决这个问题,但如果它没有破坏,我们就不需要修复它

答案 1 :(得分:0)

我知道这是一篇过时的文章,但是我需要一个函数来取消PowerPoint中每个组的分组,而不管如上所述的动画问题。我使用以下内容在检测到一组对象的情况下继续循环遍历幻灯片对象。Sub

<a class="menu_button" id="res_menu_close" href="#"></a>