利用vba代码如何选取指定区域内的所有shape对象.
发布网友
发布时间:2022-04-22 06:19
我来回答
共2个回答
热心网友
时间:2022-04-22 07:49
代码及注释如下:
Sub main()
Dim Sh1(1 To 100) As String‘定义数组,用于存放shape名
Dim sh As Shape
Dim i As Integer
With Worksheets("Sheet6")
For Each sh In .Shapes'遍历所有的Shape对象
If Not Application.Intersect(sh.TopLeftCell, .Range("A1:J20")) Is Nothing Then'Shape对象如何不在A1:J20区域中
i = i + 1'累加数量
Sh1(i) = sh.Name'将Shape名依次存放在数组Sh1中
End If
Next sh
End With
ActiveSheet.Shapes.Range(Sh1).Select,选中Sh1中存放的Shape
End Sub
热心网友
时间:2022-04-22 09:07
返回A1:D20 内SHAPE名称,名称放在A列;代码如下:
Sub aa()
Dim ms As Shape
For Each ms In Sheets("Sheet6").Shapes
If ms.BottomRightCell.Row <= 20 And ms.BottomRightCell.Column <= 10 Then
k = k + 1
Cells(k, 1) = ms.Name
End If
Next ms
End Sub