Class Shape (Excel VBA)
The class Shape represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.
The main procedures of class Shape are Copy, Delete, Select, ShapeRange.Delete, ShapeRange.Select, Shapes.Add3DModel, Shapes.AddCallout, Shapes.AddChart2, Shapes.AddConnector, Shapes.AddCurve, Shapes.AddFormControl, Shapes.AddLabel, Shapes.AddLine, Shapes.AddOLEObject, Shapes.AddPicture, Shapes.AddPicture2, Shapes.AddPolyline, Shapes.AddShape, Shapes.AddSmartArt, Shapes.AddTextbox and Shapes.AddTextEffect
Set
To use a Shape class variable it first needs to be instantiated, for example
Dim strFilename As String: strFilename =
Dim chr As Chart: Set chr =
Dim shpAdd3DModel As Shape
Set shpAdd3DModel = chr.Shapes.Add3DModel(Filename:=strFilename)
The following procedures can be used to set variables of type Shape: GroupItems, ShapeRange.GroupItems, Comment.Shape, ConnectorFormat.BeginConnectedShape, ConnectorFormat.EndConnectedShape, FreeformBuilder.ConvertToShape, GroupShapes.Item, Hyperlink.Shape, PivotCache.CreatePivotChart, PivotTable.PivotChart, Duplicate, ParentGroup, ShapeRange.Item, ShapeRange.Group, ShapeRange.ParentGroup, ShapeRange.Regroup, Shapes.Item, Shapes.Add3DModel, Shapes.AddCallout, Shapes.AddChart2, Shapes.AddConnector, Shapes.AddCurve, Shapes.AddFormControl, Shapes.AddLabel, Shapes.AddLine, Shapes.AddOLEObject, Shapes.AddPicture, Shapes.AddPicture2, Shapes.AddPolyline, Shapes.AddShape, Shapes.AddSmartArt, Shapes.AddTextbox, Shapes.AddTextEffect, Slicer.Shape, Window.RangeFromPoint, ChartObject.ShapeRange, ChartObjects.ShapeRange, GroupShapes.Range, OLEObject.ShapeRange, OLEObjects.ShapeRange, Ungroup, ShapeRange.Duplicate, ShapeRange.Ungroup, Shapes.Range, Chart.Shapes and Worksheet.Shapes
For Each
Here is an example of processing the Shape items in a collection.
Dim shp As Shape: Set shp =
Dim shpGroupItem As Shape
For Each shpGroupItem In shp.GroupItems
Next shpGroupItem
Themes
Some procedures in this class have been grouped together in themes and are described on separate theme pages
Cell with its procedures BottomRightCell and TopLeftCell
Copy with its procedures Copy and CopyPicture
3D with its procedures Model3D and ShapeRange.Model3D
Sort/Order with its procedures ZOrder, ZOrderPosition, ShapeRange.ZOrder and ShapeRange.ZOrderPosition
Add with its procedures Shapes.Add3DModel, Shapes.AddCallout, Shapes.AddChart2, Shapes.AddConnector, Shapes.AddCurve, Shapes.AddFormControl, Shapes.AddLabel, Shapes.AddLine, Shapes.AddOLEObject, Shapes.AddPicture, Shapes.AddPicture2, Shapes.AddPolyline, Shapes.AddShape, Shapes.AddSmartArt, Shapes.AddTextbox and Shapes.AddTextEffect
Methods
These are the main methods of the Shape class
Delete - Deletes the object.
Select - Selects the object.
ShapeRange.Delete - Deletes the object.
ShapeRange.Select - Selects the object.
Other Methods
ShapeRange.Align - Aligns the shapes in the specified range of shapes.
Set myDocument = Worksheets(1)
myDocument.Shapes.SelectAll
Selection.ShapeRange.Align msoAlignLefts, False
ShapeRange.Distribute - Horizontally or vertically distributes the shapes in the specified range of shapes.
Set myDocument = Worksheets(1)
With myDocument.Shapes
numShapes = .Count
If numShapes > 1 Then
numAutoShapes = 0
ReDim autoShpArray(1 To numShapes)
For i = 1 To numShapes
If .Item(i).Type = msoAutoShape Then
numAutoShapes = numAutoShapes + 1
autoShpArray(numAutoShapes) = .Item(i).Name
End If
Next
If numAutoShapes > 1 Then
ReDim Preserve autoShpArray(1 To numAutoShapes)
Set asRange = .Range(autoShpArray)
asRange.Distribute msoDistributeHorizontally, False
End If
End If
End With
Shapes.BuildFreeform - Builds a freeform object. Returns a FreeformBuilder object that represents the freeform as it is being built.
Set myDocument = Worksheets(1)
With myDocument.Shapes.BuildFreeform(msoEditingCorner, 360, 200)
.AddNodes msoSegmentCurve, msoEditingCorner, _
380, 230, 400, 250, 450, 300
.AddNodes msoSegmentCurve, msoEditingAuto, 480, 200
.AddNodes msoSegmentLine, msoEditingAuto, 480, 400
.AddNodes msoSegmentLine, msoEditingAuto, 360, 200
.ConvertToShape
End With
Properties
GroupShapes.Count returns a Long value that represents the number of objects in the collection.
GroupShapes.Parent returns the parent object for the specified object. Read-only.
GroupShapes.Range returns a ShapeRange object that represents a subset of the shapes in a Shapes collection.
Set myDocument = Worksheets(1)
myDocument.Shapes.Range(Array(1, 3)) _
.Fill.Patterned msoPatternHorizontalBrick
Adjustments returns an Adjustments object that contains adjustment values for all the adjustments in the specified shape. Applies to any Shape object that represents an AutoShape, WordArt, or Connector.
Set myDocument = Worksheets(1)
myDocument.Shapes(1).Adjustments(1) = 0.25
AlternativeText returns or sets the descriptive (alternative) text string for a Shape object when the object is saved to a webpage.
Worksheets(1).Shapes(1).AlternativeText = "Concentric circles"
AutoShapeType returns or sets the shape type for the specified Shape or ShapeRange object, which must represent an AutoShape other than a line, freeform drawing, or connector.
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes
If s.AutoShapeType = msoShape16pointStar Then
s.AutoShapeType = msoShape32pointStar
End If
Next
BackgroundStyle returns or sets the background style.
BlackWhiteMode returns or sets a value that indicates how the specified shape appears when the presentation is viewed in black-and-white mode.
Sub UseBlackWhiteMode()
Dim wksOne As Worksheet
Set wksOne = Application.Worksheets(1)
wksOne.Shapes(1).BlackWhiteMode = msoBlackWhiteGrayOutline
End Sub
Callout returns a CalloutFormat object that contains callout formatting properties for the specified shape. Applies to a Shape object that represent line callouts.
Set myDocument = Worksheets(1)
With myDocument.Shapes
.AddShape msoShapeOval, 180, 200, 280, 130
With .AddCallout(msoCalloutTwo, 420, 170, 170, 40)
.TextFrame.Characters.Text = "My oval"
With .Callout
.Accent = True
.Border = False
End With
End With
End With
Chart returns a Chart object that represents the chart contained in the shape.
Child returns msoTrue if the specified shape is a child shape or if all shapes in a shape range are child shapes of the same parent. Returns msoFalse if the selected shape is not a child shape. Returns msoTriStateMixed if only some of the selected shapes are child shapes.
ConnectionSiteCount returns the number of connection sites on the specified shape.
Set myDocument = Worksheets(1)
Set s = myDocument.Shapes
Set firstRect = s.AddShape(msoShapeRectangle, _
100, 50, 200, 100)
Set secondRect = s.AddShape(msoShapeRectangle, _
300, 300, 200, 100)
lastsite = secondRect.ConnectionSiteCount
With s.AddConnector(msoConnectorCurve, _
0, 0, 100, 100).ConnectorFormat
.BeginConnect ConnectedShape:=firstRect, _
ConnectionSite:=1
.EndConnect ConnectedShape:=secondRect, _
ConnectionSite:=1
End With
With s.AddConnector(msoConnectorCurve, _
0, 0, 100, 100).ConnectorFormat
.BeginConnect ConnectedShape:=firstRect, _
ConnectionSite:=1
.EndConnect ConnectedShape:=secondRect, _
ConnectionSite:=lastsite
End With
Connector true if the specified shape is a connector.
Set myDocument = Worksheets(1)
With myDocument.Shapes
For i = .Count To 1 Step -1
With .Item(i)
If .Connector Then .Delete
End With
Next
End With
ConnectorFormat returns a ConnectorFormat object that contains connector formatting properties. Applies to a Shape object that represents connectors.
Set myDocument = Worksheets(1)
Set s = myDocument.Shapes
Set firstRect = s.AddShape(msoShapeRectangle, 100, 50, 200, 100)
Set secondRect = s.AddShape(msoShapeRectangle, 300, 300, 200, 100)
Set c = s.AddConnector(msoConnectorCurve, 0, 0, 0, 0)
with c.ConnectorFormat
.BeginConnect firstRect, 1
.EndConnect secondRect, 1
c.RerouteConnections
.BeginDisconnect
.EndDisconnect
End With
ControlFormat returns a ControlFormat object that contains Microsoft Excel control properties.
Set lbcf = Worksheets(1).Shapes(2).ControlFormat
lbcf.RemoveItem lbcf.ListIndex
Decorative sets or returns the decorative flag for the specified object.
Fill returns a FillFormat object for a specified shape or a ChartFillFormat object for a specified chart that contains fill formatting properties for the shape or chart.
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddShape(msoShapeRectangle, _
90, 90, 90, 50).Fill
.ForeColor.RGB = RGB(128, 0, 0)
.BackColor.RGB = RGB(170, 170, 170)
.TwoColorGradient msoGradientHorizontal, 1
End With
FormControlType returns the Microsoft Excel control type.
For Each s In Worksheets(1).Shapes
If s.Type = msoFormControl Then
If s.FormControlType = xlCheckBox Then _
s.ControlFormat.Value = False
End If
Next
Glow returns a GlowFormat object for a specified shape that contains glow formatting properties for the shape.
GraphicStyle returns or sets an MsoGraphicStyleIndex constant that represents the style of an SVG graphic.
Dim myShape As Shape
Set myShape = ActiveDocument.Shapes(1)
myShape.GraphicStyle = msoGraphicStylePreset22
GroupItems returns a GroupShapes object that represents the individual shapes in the specified group. Use the Item method of the GroupShapes object to return a single shape from the group. Applies to Shape objects that represent grouped shapes.
Set myDocument = Worksheets(1)
With myDocument.Shapes
.AddShape(msoShapeIsoscelesTriangle, _
10, 10, 100, 100).Name = "shpOne"
.AddShape(msoShapeIsoscelesTriangle, _
150, 10, 100, 100).Name = "shpTwo"
.AddShape(msoShapeIsoscelesTriangle, _
300, 10, 100, 100).Name = "shpThree"
With .Range(Array("shpOne", "shpTwo", "shpThree")).Group
.Fill.PresetTextured msoTextureBlueTissuePaper
.GroupItems(2).Fill.PresetTextured msoTextureGreenMarble
End With
End With
HasChart returns whether a shape contains a chart.
HasSmartArt returns whether there is a SmartArt diagram present on the specified shape.
Height returns or sets a Single value that represents the height, in points, of the object.
HorizontalFlip true if the specified shape is flipped around the horizontal axis.
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes
If s.HorizontalFlip Then s.Flip msoFlipHorizontal
If s.VerticalFlip Then s.Flip msoFlipVertical
Next
Hyperlink returns a Hyperlink object that represents the hyperlink for the shape.
Worksheets(1).Shapes(1).Hyperlink.Follow NewWindow:=True
ID returns a Long value that represents the type for the specified object.
Left returns or sets a Single value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).
Line returns a LineFormat object that contains line formatting properties for the specified shape. (For a line, the LineFormat object represents the line itself; for a shape with a border, the LineFormat object represents the border).
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddLine(10, 10, 250, 250).Line
.DashStyle = msoLineDashDotDot
.ForeColor.RGB = RGB(50, 0, 128)
End With
LinkFormat returns a LinkFormat object that contains linked OLE object properties.
For Each s In Worksheets(1).Shapes
If s.Type = msoLinkedOLEObject Then s.LinkFormat.Update
Next
LockAspectRatio true if the specified shape retains its original proportions when you resize it. False if you can change the height and width of the shape independently of one another when you resize it.
Set myDocument = Worksheets(1)
myDocument.Shapes.AddShape(msoShapeCube, _
50, 50, 100, 200).LockAspectRatio = msoTrue
Locked returns or sets a Boolean value that indicates if the object is locked.
Name returns or sets a String value representing the name of the object.
Nodes returns a ShapeNodes collection that represents the geometric description of the specified shape.
Set myDocument = Worksheets(1)
With myDocument.Shapes(3).Nodes
.Insert 4, msoSegmentCurve, msoEditingSmooth, 210, 100
End With
OLEFormat returns an OLEFormat object that contains OLE object properties.
Worksheets(1).Shapes(1).OLEFormat.Activate
OnAction returns or sets the name of a macro that's run when the specified object is chosen.
Worksheets(1).Shapes(1).OnAction = "ShapeClick"
Parent returns the parent object for the specified object. Read-only.
ParentGroup returns a Shape object that represents the common parent shape of a child shape or a range of child shapes.
Sub ParentGroup()
Dim pgShape As Shape
With ActiveSheet.Shapes
.AddShape Type:=1, Left:=10, Top:=10, _
Width:=100, Height:=100
.AddShape Type:=2, Left:=110, Top:=120, _
Width:=100, Height:=100
.Range(Array(1, 2)).Group
End With
' Using the child shape in the group get the Parent shape.
Set pgShape = ActiveSheet.Shapes(1).GroupItems(1).ParentGroup
MsgBox "The two shapes will now be deleted."
' Delete the parent shape.
pgShape.Delete
End Sub
PictureFormat returns a PictureFormat object that contains picture formatting properties for the specified shape. Applies to a Shape object that represents pictures or OLE objects.
Set myDocument = Worksheets(1)
With myDocument.Shapes(1).PictureFormat
.Brightness = 0.3
.Contrast = .75
End With
Placement returns or sets an XlPlacement value that represents the way the object is attached to the cells below it.
Reflection returns a ReflectionFormat object for a specified shape that contains reflection formatting properties for the shape.
Rotation returns or sets the rotation of the shape, in degrees.
Shadow returns a read-only ShadowFormat object that contains shadow formatting properties for the specified shape or shapes.
ShapeStyle returns or sets an MsoShapeStyleIndex value that represents the shape style of the shape range.
SmartArt returns an object that represents the SmartArt associated with the shape.
SoftEdge returns a SoftEdgeFormat object for a specified shape that contains soft edge formatting properties for the shape.
TextEffect returns a TextEffectFormat object that contains text-effect formatting properties for the specified shape.
Set myDocument = Worksheets(1)
With myDocument.Shapes(3)
If .Type = msoTextEffect Then
.TextEffect.FontBold = True
End If
End With
TextFrame returns a TextFrame object that contains the alignment and anchoring properties for the specified shape.
Worksheets(1).Shapes(1).TextFrame _
.HorizontalAlignment = xlHAlignJustify
TextFrame2 returns a TextFrame2 object that contains text formatting for the specified shape.
ThreeD returns a ThreeDFormat object that contains 3D-effect formatting properties for the specified shape.
Set myDocument = Worksheets(1)
With myDocument.Shapes(1).ThreeD
.Visible = True
.Depth = 50
.ExtrusionColor.RGB = RGB(255, 100, 255)
' RGB value for purple
.SetExtrusionDirection msoExtrusionTop
.PresetLightingDirection = msoLightingLeft
End With
Title returns or sets the title of the alternative text associated with the specified shape.
Top returns or sets a Single value that represents the distance, in points, from the top edge of the topmost shape in the shape range to the top edge of the worksheet.
Type returns or sets an MsoShapeType value that represents the shape type.
VerticalFlip true if the specified shape is flipped around the vertical axis.
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes
If s.HorizontalFlip Then s.Flip msoFlipHorizontal
If s.VerticalFlip Then s.Flip msoFlipVertical
Next
Vertices returns the coordinates of the specified freeform drawing's vertices (and control points for Bézier curves) as a series of coordinate pairs. You can use the array returned by this property as an argument to the AddCurve method or AddPolyLine method.
Set myDocument = Worksheets(1)
With myDocument.Shapes(1)
vertArray = .Vertices
x1 = vertArray(1, 1)
y1 = vertArray(1, 2)
MsgBox "First vertex coordinates: " & x1 & ", " & y1
End With
Visible returns or sets an MsoTriState value that determines whether the object is visible.
Width returns or sets a Single value that represents the width, in points, of the object.
ShapeRange.Adjustments returns an Adjustments object that contains adjustment values for all the adjustments in the specified shape. Applies to any ShapeRange object that represents an AutoShape, WordArt, or Connector.
ShapeRange.AlternativeText returns or sets the descriptive (alternative) text string for a ShapeRange object when the object is saved to a webpage.
ShapeRange.AutoShapeType returns or sets the shape type for the specified Shape or ShapeRange object, which must represent an AutoShape other than a line, freeform drawing, or connector.
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes
If s.AutoShapeType = msoShape16pointStar Then
s.AutoShapeType = msoShape32pointStar
End If
Next
ShapeRange.BackgroundStyle returns or sets the background style.
ShapeRange.BlackWhiteMode returns or sets a value that indicates how the specified shape appears when the presentation is viewed in black-and-white mode.
Sub UseBlackWhiteMode()
Dim wksOne As Worksheet
Set wksOne = Application.Worksheets(1)
wksOne.Shapes(1).BlackWhiteMode = msoBlackWhiteGrayOutline
End Sub
ShapeRange.Callout returns a CalloutFormat object that contains callout formatting properties for the specified shape. Applies to ShapeRange objects that represent line callouts.
Set myDocument = Worksheets(1)
With myDocument.Shapes
.AddShape msoShapeOval, 180, 200, 280, 130
With .AddCallout(msoCalloutTwo, 420, 170, 170, 40)
.TextFrame.Characters.Text = "My oval"
With .Callout
.Accent = True
.Border = False
End With
End With
End With
ShapeRange.Chart returns a Chart object that represents the chart contained in the shape range.
ShapeRange.Child returns msoTrue if the specified shape is a child shape or if all shapes in a shape range are child shapes of the same parent. Returns msoFalse if the selected shape is not a child shape. Returns msoTriStateMixed if only some of the selected shapes are child shapes.
Sub FillChildShape()
'Select the first shape in the drawing canvas.
ActiveSheet.Shapes(1).CanvasItems(1).Select
'Fill selected shape if it is a child shape.
If Selection.ShapeRange.Child = msoTrue Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(100, 0, 200)
Else
MsgBox "This shape is not a child shape."
End If
End Sub
ShapeRange.ConnectionSiteCount returns the number of connection sites on the specified shape.
Set myDocument = Worksheets(1)
Set s = myDocument.Shapes
Set firstRect = s.AddShape(msoShapeRectangle, _
100, 50, 200, 100)
Set secondRect = s.AddShape(msoShapeRectangle, _
300, 300, 200, 100)
lastsite = secondRect.ConnectionSiteCount
With s.AddConnector(msoConnectorCurve, _
0, 0, 100, 100).ConnectorFormat
.BeginConnect ConnectedShape:=firstRect, _
ConnectionSite:=1
.EndConnect ConnectedShape:=secondRect, _
ConnectionSite:=1
End With
With s.AddConnector(msoConnectorCurve, _
0, 0, 100, 100).ConnectorFormat
.BeginConnect ConnectedShape:=firstRect, _
ConnectionSite:=1
.EndConnect ConnectedShape:=secondRect, _
ConnectionSite:=lastsite
End With
ShapeRange.Connector true if the specified shape is a connector.
Set myDocument = Worksheets(1)
With myDocument.Shapes
For i = .Count To 1 Step -1
With .Item(i)
If .Connector Then .Delete
End With
Next
End With
ShapeRange.ConnectorFormat returns a ConnectorFormat object that contains connector formatting properties. Applies to ShapeRange objects that represent connectors.
Set myDocument = Worksheets(1)
Set s = myDocument.Shapes
Set firstRect = s.AddShape(msoShapeRectangle, 100, 50, 200, 100)
Set secondRect = s.AddShape(msoShapeRectangle, 300, 300, 200, 100)
Set c = s.AddConnector(msoConnectorCurve, 0, 0, 0, 0)
with c.ConnectorFormat
.BeginConnect firstRect, 1
.EndConnect secondRect, 1
c.RerouteConnections
.BeginDisconnect
.EndDisconnect
End With
ShapeRange.Count returns a Long value that represents the number of objects in the collection.
ShapeRange.Decorative sets or returns the decorative flag for the specified object.
ShapeRange.Fill returns a FillFormat object for a specified shape or a ChartFillFormat object for a specified chart that contains fill formatting properties for the shape or chart.
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddShape(msoShapeRectangle, _
90, 90, 90, 50).Fill
.ForeColor.RGB = RGB(128, 0, 0)
.BackColor.RGB = RGB(170, 170, 170)
.TwoColorGradient msoGradientHorizontal, 1
End With
ShapeRange.Glow returns a GlowFormat object for a specified shape range that contains glow formatting properties for the shape range.
ShapeRange.GraphicStyle returns or sets an MsoGraphicStyleIndex constant that represents the style of a shape range containing one or more SVG graphics.
ShapeRange.GroupItems returns a GroupShapes object that represents the individual shapes in the specified group. Use the Item method of the GroupShapes object to return a single shape from the group. Applies to ShapeRange objects that represent grouped shapes.
Set myDocument = Worksheets(1)
With myDocument.Shapes
.AddShape(msoShapeIsoscelesTriangle, _
10, 10, 100, 100).Name = "shpOne"
.AddShape(msoShapeIsoscelesTriangle, _
150, 10, 100, 100).Name = "shpTwo"
.AddShape(msoShapeIsoscelesTriangle, _
300, 10, 100, 100).Name = "shpThree"
With .Range(Array("shpOne", "shpTwo", "shpThree")).Group
.Fill.PresetTextured msoTextureBlueTissuePaper
.GroupItems(2).Fill.PresetTextured msoTextureGreenMarble
End With
End With
ShapeRange.HasChart returns whether a shape range contains a chart.
ShapeRange.Height returns or sets a Single value that represents the height, in points, of the object.
ShapeRange.HorizontalFlip true if the specified shape is flipped around the horizontal axis.
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes
If s.HorizontalFlip Then s.Flip msoFlipHorizontal
If s.VerticalFlip Then s.Flip msoFlipVertical
Next
ShapeRange.ID returns a Long value that represents the type for the specified object.
ShapeRange.Left returns or sets a Single value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).
ShapeRange.Line returns a LineFormat object that contains line formatting properties for the specified shape. (For a line, the LineFormat object represents the line itself; for a shape with a border, the LineFormat object represents the border).
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddLine(10, 10, 250, 250).Line
.DashStyle = msoLineDashDotDot
.ForeColor.RGB = RGB(50, 0, 128)
End With
ShapeRange.LockAspectRatio true if the specified shape retains its original proportions when you resize it. False if you can change the height and width of the shape independently of one another when you resize it.
Set myDocument = Worksheets(1)
myDocument.Shapes.AddShape(msoShapeCube, _
50, 50, 100, 200).LockAspectRatio = msoTrue
ShapeRange.Name returns or sets a String value representing the name of the object.
ShapeRange.Nodes returns a ShapeNodes collection that represents the geometric description of the specified shape.
Set myDocument = Worksheets(1)
With myDocument.Shapes(3).Nodes
.Insert 4, msoSegmentCurve, msoEditingSmooth, 210, 100
End With
ShapeRange.Parent returns the parent object for the specified object. Read-only.
ShapeRange.ParentGroup returns a Shape object that represents the common parent shape of a child shape or a range of child shapes.
Sub ParentGroup()
Dim pgShape As Shape
With ActiveSheet.Shapes
.AddShape Type:=1, Left:=10, Top:=10, _
Width:=100, Height:=100
.AddShape Type:=2, Left:=110, Top:=120, _
Width:=100, Height:=100
.Range(Array(1, 2)).Group
End With
' Using the child shape in the group get the Parent shape.
Set pgShape = ActiveSheet.Shapes(1).GroupItems(1).ParentGroup
MsgBox "The two shapes will now be deleted."
' Delete the parent shape.
pgShape.Delete
End Sub
ShapeRange.PictureFormat returns a PictureFormat object that contains picture formatting properties for the specified shape. Applies to a ShapeRange object that represent pictures or OLE objects.
Set myDocument = Worksheets(1)
With myDocument.Shapes(1).PictureFormat
.Brightness = 0.3
.Contrast = .75
End With
ShapeRange.Reflection returns a ReflectionFormat object for a specified shape range that contains reflection formatting properties for the shape range.
ShapeRange.Rotation returns or sets the rotation of the shape, in degrees.
ShapeRange.Shadow returns a read-only ShadowFormat object that contains shadow formatting properties for the specified shape or shapes.
ShapeRange.ShapeStyle returns or sets an MsoShapeStyleIndex value that represents the shape style of the shape range.
ShapeRange.SoftEdge returns a SoftEdgeFormat object for a specified shape range that contains soft edge formatting properties for the shape range.
ShapeRange.TextEffect returns a TextEffectFormat object that contains text-effect formatting properties for the specified shape.
Set myDocument = Worksheets(1)
With myDocument.Shapes(3)
If .Type = msoTextEffect Then
.TextEffect.FontBold = True
End If
End With
ShapeRange.TextFrame returns a TextFrame object that contains the alignment and anchoring properties for the specified shape.
Worksheets(1).Shapes(1).TextFrame _
.HorizontalAlignment = xlHAlignJustify
ShapeRange.TextFrame2 returns a TextFrame2 object that contains text formatting for the specified shape range.
ShapeRange.ThreeD returns a ThreeDFormat object that contains 3D-effect formatting properties for the specified shape.
Set myDocument = Worksheets(1)
With myDocument.Shapes(1).ThreeD
.Visible = True
.Depth = 50
.ExtrusionColor.RGB = RGB(255, 100, 255)
' RGB value for purple
.SetExtrusionDirection msoExtrusionTop
.PresetLightingDirection = msoLightingLeft
End With
ShapeRange.Title returns or sets the title of the alternative text associated with the specified shape range.
ShapeRange.Top returns or sets a Single value that represents the distance, in points, from the top edge of the topmost shape in the shape range to the top edge of the worksheet.
ShapeRange.Type returns an MsoShapeType value that represents the shape type.
ShapeRange.VerticalFlip true if the specified shape is flipped around the vertical axis.
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes
If s.HorizontalFlip Then s.Flip msoFlipHorizontal
If s.VerticalFlip Then s.Flip msoFlipVertical
Next
ShapeRange.Vertices returns the coordinates of the specified freeform drawing's vertices (and control points for Bézier curves) as a series of coordinate pairs. You can use the array returned by this property as an argument to the AddCurve method or AddPolyLine method.
Set myDocument = Worksheets(1)
With myDocument.Shapes(1)
vertArray = .Vertices
x1 = vertArray(1, 1)
y1 = vertArray(1, 2)
MsgBox "First vertex coordinates: " & x1 & ", " & y1
End With
ShapeRange.Visible returns or sets an MsoTriState value that determines whether the object is visible.
ShapeRange.Width returns or sets a Single value that represents the width, in points, of the object.
Shapes.Count returns a Long value that represents the number of objects in the collection.
Shapes.Parent returns the parent object for the specified object. Read-only.
Shapes.Range returns a ShapeRange object that represents a subset of the shapes in a Shapes collection.
Dim arShapes() As Variant
Dim objRange As Object
arShapes = Array("Oval 4", "Rectangle 5")
Set objRange = ActiveSheet.Shapes.Range(arShapes)