如何根据范围选择多个形状? [英] How to select multiple shapes based on range?
本文介绍了如何根据范围选择多个形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果所选范围由1个单元组成,则选择工作表中的所有形状,否则选择范围内的形状。这是给我麻烦的其他部分。我可以选择一个形状,但不能在范围内的所有形状...
If the selected range is composed of 1 cell then select all shapes in the sheet, else select the shapes in the range. It's the "else" part that's giving me trouble. I can select one shape, but not all shapes in the range...
Public Sub ShapeSelection()
Dim Sh As Shape
On Error Resume Next
If Selection.Rows.count * Selection.Columns.count = 1 Then
ActiveSheet.Shapes.SelectAll
Else
Application.ScreenUpdating = False
With ActiveSheet
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, .Range(Selection.Address)) Is Nothing Then
Sh.Select
End If
Next Sh
End With
Application.ScreenUpdating = True
End If
End Sub
推荐答案
尝试这个。请注意包含False一词:
Try this. Note the inclusion of the word "False":
Public Sub ShapeSelection()
Dim Sh As Shape
Dim selectedOne As Boolean
On Error Resume Next
If Selection.Rows.count * Selection.Columns.count = 1 Then
ActiveSheet.Shapes.SelectAll
Else
Application.ScreenUpdating = False
With ActiveSheet
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, .Range(Selection.Address)) Is Nothing Then
If selectedOne = False Then
Sh.Select
selectedOne = True
Else
Sh.Select(False)
End If
End If
Next Sh
End With
Application.ScreenUpdating = True
End If
End Sub
这篇关于如何根据范围选择多个形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文