office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

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

有关形状的一些操作函数

2020-05-27 08:00:00
zstmtony
原创
110
判断指定的图形形状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

分享