我面临运行时错误 9:以下代码的下标超出范围,但最初运行良好。但是后来当我协作所有模块来创建加载项时,它显示错误。
Sub SelectSimilarshapes()
Dim sh As Shape
Dim shapeCollection() As String
Set sh = ActiveWindow.Selection.ShapeRange(1)
ReDim Preserve shapeCollection(0)
shapeCollection(0) = sh.Name
Dim otherShape As Shape
Dim iShape As Integer
iShape = 1
For Each otherShape In ActiveWindow.View.Slide.Shapes
If otherShape.Type = sh.Type _
And otherShape.AutoShapeType = sh.AutoShapeType _
And otherShape.Type <> msoPlaceholder Then
If (otherShape.Name <> sh.Name) Then
ReDim Preserve shapeCollection(1 + iShape)
shapeCollection(iShape) = otherShape.Name
iShape = iShape + 1
End If
End If
Next otherShape
ActiveWindow.View.Slide.Shapes.Range(shapeCollection).Select
Select Case iShape
Case 1
MsgBox "Sorry, no shapes matching your search criteria were found"
Case Else
MsgBox "Shapes matching your search criteria were found and are selected"
End Select
NormalExit:
Exit Sub
err1:
MsgBox "You haven't selected any object"
Resume NormalExit:
End Sub