office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Excel Vba代碼穫取指定區域內的所有shape對象

2019-10-28 15:23:00
tmtony8
原創
10934

在Excel裡,希望選取某箇工作錶中指定區域的所有形狀對象

運行代碼,選中A1:D10 區域中的所有shape對象


Sub main()
    Dim Sh1(1 To 100) As String  '定義數組,用於存放shape名
    Dim sh As Shape
    Dim i As Integer
    With ActiveSheet
        For Each sh In .Shapes '遍歷所有的Shape對象
            If Not Application.Intersect(sh.TopLeftCell, .Range("A1:D10")) Is Nothing Then '   判斷Shape對象是否在指定的A1:D10區域中
                i = i + 1  '統計總共有多少箇形狀
                Sh1(i) = sh.Name   '將Shape名保存在數組
            End If
        Next sh
    End With
    ActiveSheet.Shapes.Range(Sh1).Select '選中Sh1中存放的Shape
End Sub


    分享