office交流網--QQ交流群號

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

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

有關形狀的一些操作函數

2020-05-27 08:00:00
zstmtony
原創
2549
判斷指定的圖形形狀shape是否存在


Function shapeExists(shapeName As String) As Boolean
'returns TRUE if a shape named [ShapeName] exists on the active worksheet
Dim sh As Shape
For Each sh In ActiveSheet.Shapes
If sh.Name = shapeName Then shapeExists = True
Next sh
End Function
Example usage:

If Not shapeExists("My Shape Name") Then MsgBox "Shape not found!"
List All Shapes


列齣當前工作錶中所有圖形形狀(shape)

Sub ListAllShapes()
'list all shapes on the active worksheet
Dim sh As Shape
For Each sh In ActiveSheet.Shapes
Debug.Print "id=" & sh.ID, "name=" & sh.Name
Next sh
End Sub

刪除所有形狀

Sub DeleteAllShapes()
'delete all shapes on the active worksheet (Including CONTROLS, so use with caution!)
Dim sh As Shape
For Each sh In ActiveSheet.Shapes
sh.Delete
Next sh

End Sub



Sub 判斷形狀是否存在()  
    On Error GoTo info
    Sheet1.Shapes("test").Select
    Exit Sub
info:
    MsgBox "不存在此形狀"
End Sub

分享