Program with Drawing Objects
Any object that can be drawn is considered a Shape object in Excel. You get individual Shape objects from the Worksheet or Chart object’s Shapes collection. The Shape object is unusual because it encapsulates the members from more specific object types. Because of that, any given Shape object may or may not support any given Shape member. For example, the following code flips simple shapes on a worksheet, doesn’t affect embedded objects, and causes an error if the worksheet contains a diagram:
Sub FlipObjects( )
Dim s As Shape
For Each s In ActiveSheet.Shapes
' Doesn't affect embedded objects. Error on diagrams!
s.Flip msoFlipHorizontal
Next
End SubThere are three general categories of Shape objects. You can determine the category of a Shape object by comparing its Type property to those listed in Table 18-1.
Table 18-1. Use the Type property to determine which Shape members are available
|
Category |
Shape Type |
Programming notes |
|---|---|---|
|
Simple shapes |
|
Most |
|
Embedded objects |
|
Convert these objects to a specific type for access to their members. |
|
Diagram shapes |
|
Accessing most |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access