我正在尝试选择幻灯片1中提供的所有对象(形状)并对其进行分组。
我想从形状的选择中排除标题和表格。
我还想排除包含文本“Source”的形状。
我在“取消选择”时遇到错误。
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


发布于 2019-11-22 02:50:22
您的错误可能是由下面这一行引起的:
Shp.TextFrame.TextRange = "Source"这应该是:
Shp.TextFrame.TextRange.Text = "Source"但总的来说,你的方法的问题是,最好只选择你想要的形状,而不是选择所有的形状并试图取消选择它们。这应该能更好地工作:
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"),但您可以很容易地修改测试函数,以获得您想要排除的内容。
https://stackoverflow.com/questions/58968569
复制相似问题