首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多选形状,并根据PowerPoint幻灯片中的条件取消选择特定形状

多选形状,并根据PowerPoint幻灯片中的条件取消选择特定形状
EN

Stack Overflow用户
提问于 2019-11-21 14:29:03
回答 1查看 327关注 0票数 0

我正在尝试选择幻灯片1中提供的所有对象(形状)并对其进行分组。

我想从形状的选择中排除标题和表格。

我还想排除包含文本“Source”的形状。

我在“取消选择”时遇到错误。

代码语言:javascript
复制
Sub Selectunselect()

Dim Shp As Shape
Dim curSlide As Long

ActivePresentation.Slides(1).Shapes.SelectAll

For Each Shp In ActiveWindow.Selection.ShapeRange
    If Shp.HasTable Then
        Shp.Unselect
    End If
Next Shp


    If Shp.HasTitle Then
        Shp.Unselect
    End If
Next Shp


    If Shp.TextFrame.TextRange = "Source" Then
        Shp.Unselect
    End If
Next Shp


    If Shp.TextFrame.HasText And Shp.TextFrame.TextRange.Text = "Source*" Then
        Shp.Unselect
    End If
Next Shp

End Sub

EN

回答 1

Stack Overflow用户

发布于 2019-11-22 02:50:22

您的错误可能是由下面这一行引起的:

代码语言:javascript
复制
Shp.TextFrame.TextRange = "Source"

这应该是:

代码语言:javascript
复制
Shp.TextFrame.TextRange.Text = "Source"

但总的来说,你的方法的问题是,最好只选择你想要的形状,而不是选择所有的形状并试图取消选择它们。这应该能更好地工作:

代码语言:javascript
复制
Public Sub SelectAllShapes()


            Dim shapeCollection() As Variant
            Dim shpCounter As Long
            Dim oShp As Shape
            Dim currentSlide As Slide

            Set currentSlide = Application.ActiveWindow.View.Slide

            shpCounter = 0
            ReDim shapeCollection(shpCounter)

            For Each oShp In currentSlide.Shapes

            If oShp.Type <> msoPlaceholder And IsItSource(oShp) = False Then
                ReDim Preserve shapeCollection(shpCounter)
                shapeCollection(shpCounter) = oShp.Name
                shpCounter = shpCounter + 1
            End If

            Next

            currentSlide.Shapes.Range(shapeCollection).Select


End Sub


Public Function IsItSource(oShp As Shape) As Boolean

    If oShp.HasTextFrame = False Then
        IsItSource = False
    ElseIf oShp.TextFrame.HasText = False Then
        IsItSource = False
    Else
        If oShp.TextFrame.TextRange.text = "Source" Then
            IsItSource = True
        Else
            IsItSource = False
        End If
    End If

End Function

作为一种快捷方式,我没有编写一个单独的函数来检查标题或表格(附加的函数只检查占位符和文本"Source"),但您可以很容易地修改测试函数,以获得您想要排除的内容。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58968569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档