0% found this document useful (0 votes)
166 views44 pages

Shape Object Descargas de Internet

This document provides information about the Shape object in Excel. It describes that the Shape object represents a single shape on a worksheet and is a member of the Shapes collection, which contains all shapes in a workbook. It also lists the properties and methods available for the Shape object and provides examples of how to return, modify, and add shapes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views44 pages

Shape Object Descargas de Internet

This document provides information about the Shape object in Excel. It describes that the Shape object represents a single shape on a worksheet and is a member of the Shapes collection, which contains all shapes in a workbook. It also lists the properties and methods available for the Shape object and provides examples of how to return, modify, and add shapes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Shape Object (Excel)

Office 2013 and later


Other Versions

Represents an object in the drawing layer, such as an AutoShape, freeform, OLE object, or picture.
Remarks
The Shape object is a member of the Shapes collection. The Shapes collection contains all the
shapes in a workbook.

Note

There are three objects that represent shapes: the Shapes collection, which represents all the
shapes on a workbook; the ShapeRange collection, which represents a specified subset of the
shapes on a workbook (for example, a ShapeRange object could represent shapes one and
four in the workbook, or it could represent all the selected shapes in the workbook); and
the Shape object, which represents a single shape on a worksheet. If you want to work with
several shapes at the same time or with shapes within the selection, use
a ShapeRange collection.

Using the Shape Object


The following sections describes how to:
Return the shapes attached to the ends of a connector.
Return a newly created freeform.
Return a single shape from within a group.
Return a newly formed group of shapes.
Return an existing shape.
Return a shape within the selection.
Returning the Shapes Attached to the Ends of a Connector
To return a Shape object that represents one of the shapes attached by a connector, use
the BeginConnectedShape or EndConnectedShape property.
Returning a newly created freeform
Use the BuildFreeform and AddNodes methods to define the geometry of a new freeform, and use
the ConvertToShape method to create the freeform and return the Shape object that represents it.
Returning a Single Shape from Within a Group
Use GroupItems(index), where index is the shape name or the index number within the group, to
return a Shape object that represents a single shape in a grouped shape.
Returning a Newly Formed Group of Shapes
Use the Group or Regroup method to group a range of shapes and return a single Shape object
that represents the newly formed group. After a group has been formed, you can work with the
group the same way you work with any other shape.
Returning an Existing Shape
Use Shapes(index), where index is the shape name or the index number, to return a Shape object
that represents a shape.
Returning a Shape Within the Selection
Use Selection.ShapeRange(index), where index is the shape name or the index number, to return
a Shape object that represents a shape within the selection.
Example
The following example horizontally flips shape one and the shape named Rectangle 1
on myDocument.
VBA
Set myDocument = Worksheets(1)
myDocument.Shapes(1).Flip msoFlipHorizontal
myDocument.Shapes("Rectangle 1").Flip msoFlipHorizontal

Each shape is assigned a default name when you add it to the Shapes collection. To give the shape a
more meaningful name, use the Name property. The following example adds a rectangle to
myDocument, gives it the name Red Square, and then sets its foreground color and line style.
VBA
Set myDocument = Worksheets(1)
With myDocument.Shapes.AddShape(msoShapeRectangle, _
144, 144, 72, 72)
.Name = "Red Square"
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Line.DashStyle = msoLineDashDot
End With

The following example sets the fill for the first shape in the selection in the active window, assuming
that theres at least one shape in the selection.
VBA
ActiveWindow.Selection.ShapeRange(1).Fill.ForeColor.RGB = _
RGB(255, 0, 0)

Methods
Name

Apply

Copy

CopyPicture

Cut

Delete
Duplicate

Flip

IncrementLeft

IncrementRotation

IncrementTop

PickUp

RerouteConnections

ScaleHeight

ScaleWidth

Select

SetShapesDefaultProperties

Ungroup

ZOrder

Properties
Name

Adjustments

AlternativeText

Application

AutoShapeType

BackgroundStyle

BlackWhiteMode

BottomRightCell
Callout

Chart

Child

ConnectionSiteCount

Connector

ConnectorFormat

ControlFormat

Creator

Fill

FormControlType

Glow

GroupItems

HasChart

HasSmartArt

Height

HorizontalFlip

Hyperlink

ID

Left

Line

LinkFormat
LockAspectRatio

Locked

Name

Nodes

OLEFormat

OnAction

Parent

ParentGroup

PictureFormat

Placement

Reflection

Rotation

Shadow

ShapeStyle

SmartArt

SoftEdge

TextEffect

TextFrame

TextFrame2

ThreeD

Title
Top

TopLeftCell

Type

VerticalFlip

Vertices

Visible

Width

ZOrderPosition
Shapes.AddCurve Method (Excel)
Office 2013 and later
Other Versions

Returns a Shape object that represents a B?zier curve in a worksheet.


Syntax
expression .AddCurve(SafeArrayOfPoints)
expression A variable that represents a Shapes object.
Parameters
Data
Name Required/Optional Description
Type

SafeArrayOfPoints Required Variant An array of coordinate pairs that


specifies the vertices and control points
of the curve. The first point you
specify is the starting vertex, and the
next two points are control points for
the first B?zier segment. Then, for each
additional segment of the curve, you
specify a vertex and two control points.
The last point you specify is the ending
vertex for the curve. Note that you
must always specify 3n + 1 points,
where n is the number of segments in
the curve.

Return Value
Shape
Example
The following example adds a two-segment B?zier curve to myDocument.
VBA
Dim pts(1 To 7, 1 To 2) As Single
pts(1, 1) = 0
pts(1, 2) = 0
pts(2, 1) = 72
pts(2, 2) = 72
pts(3, 1) = 100
pts(3, 2) = 40
pts(4, 1) = 20
pts(4, 2) = 50
pts(5, 1) = 90
pts(5, 2) = 120
pts(6, 1) = 60
pts(6, 2) = 30
pts(7, 1) = 150
pts(7, 2) = 90
Set myDocument = Worksheets(1)
myDocument.Shapes.AddCurve SafeArrayOfPoints:=pts

See also
Concepts
Shapes Object
Other resources
Shapes Object Members
Shapes.AddTextbox Method
(Excel)
Office 2013 and later
Other Versions

Creates a text box. Returns a Shape object that represents the new text box.
Syntax
expression .AddTextbox(Orientation, Left, Top, Width, Height)
expression A variable that represents a Shapes object.
Parameters
Name Required/Optional Data Type Description

Orientation Required MsoTextOrientation The orientation of the textbox.

Left Required Single The position (in points) of the


upper-left corner of the text box
relative to the upper-left corner
of the document.

Top Required Single The position (in points) of the


upper-left corner of the text box
relative to the top of the
document.

Width Required Single The width of the text box, in


points.

Height Required Single The height of the text box, in


points.

Return Value
Shape
Example
This example adds a text box that contains the text "Test Box" to myDocument.
VBA
Set myDocument = Worksheets(1)
myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
100, 100, 200, 50) _
.TextFrame.Characters.Text = "Test Box"
See also
Concepts
Shapes Object
Other resources
Shapes Object Members
MsoTextOrientation Enumeration
(Office)
Office 2013 and later
Other Versions

Specifies orientation for text.

Name Value Description

msoTextOrientationDownward 3 Downward.

msoTextOrientationHorizontal 1 Horizontal.

msoTextOrientationHorizontalRotatedFarEast 6 Horizontal and rotated as


required for Asian language
support.

msoTextOrientationMixed -2 Not supported.

msoTextOrientationUpward 2 Upward.

msoTextOrientationVertical 5 Vertical.

msoTextOrientationVerticalFarEast 4 Vertical as required for Asian


language support.
MsoTextFontAlign Enumeration
(Office)
Office 2013 and later
Other Versions

Indicates the text alignment scheme used for an object.

Name Value Description

msoFontAlignAuto 0 Specifies that the text alignment will be determined by the


Office application.

msoFontAlignBaseline 3 Specifies that the font is aligned to the baseline of the


object.

msoFontAlignBottom 4 Specifies that the font is aligned to the bottom of the


object.

msoFontAlignCenter 2 Specifies that the font is aligned to the center of the object.

msoFontAlignMixed -2 Specifies that there is a mix of text alignments used with


the object.

msoFontAlignTop 1 Specifies that the font is aligned to the top of the object.
Shapes.BuildFreeform Method
(Excel)
Office 2013 and later
Other Versions
Builds a freeform object. Returns a FreeformBuilder object that represents the freeform as it is
being built. Use the AddNodes method to add segments to the freeform. After you have added at
least one segment to the freeform, you can use the ConvertToShape method to convert
the FreeformBuilder object into a Shape object that has the geometric description you?ve defined
in the FreeformBuilder object.
Syntax
expression .BuildFreeform(EditingType, X1, Y1)
expression A variable that represents a Shapes object.
Parameters
Name Required/Optional Data Type Description

EditingType Required MsoEditingType The editing property of the first


node.

X1 Required Single The position (in points) of the first


node in the freeform drawing
relative to the upper-left corner of
the document.

Y1 Required Single The position (in points) of the first


node in the freeform drawing
relative to the upper-left corner of
the document.

Return Value
FreeformBuilder
Example
This example adds a freeform with five vertices to myDocument.
VBA
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

See also
Concepts
Shapes Object
Other resources
Shapes Object Members
FreeformBuilder Object (Excel)
Office 2013 and later

Other Versions

Represents the geometry of a freeform while its being built.


Remarks
Use the BuildFreeform method to return a FreeformBuilder object. Use the AddNodes method to
add nodes to the freefrom. Use the ConvertToShape method to create the shape defined in
the FreeformBuilder object and add it to the Shapes collection.
Example
The following example adds a freeform with four segments to myDocument.
VBA
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
See also
Concepts
Excel Object Model Reference

Other resources
FreeformBuilder Object Members

PrintShare
FreeformBuilder.AddNodes
Method (Excel)
Office 2013 and later

Other Versions

Adds a point in the current shape and then draws a line from the current node to last node that was
added.
Syntax
expression .AddNodes(SegmentType, EditingType, X1, Y1, X2, Y2, X3, Y3)
expression A variable that represents a FreeformBuilder object.
Parameters
Name Required/Optional Data Type Description

SegmentType Required MsoSegmentType The type of segment to be added.

EditingType Required MsoEditingType The editing property of the vertex.

X1 Required Single If the EditingType of the new


segment is msoEditingAuto, this
argument specifies the horizontal
distance (in points) from the
upper-left corner of the document
to the end point of the new
segment. If the EditingType of the
new node is msoEditingCorner,
this argument specifies the
horizontal distance (in points)
from the upper-left corner of the
document to the first control point
for the new segment.

Y1 Required Single If the EditingType of the new


segment is msoEditingAuto, this
argument specifies the horizontal
distance (in points) from the
upper-left corner of the document
to the end point of the new
segment. If the EditingType of the
new node is msoEditingCorner,
this argument specifies the
horizontal distance (in points)
from the upper-left corner of the
document to the first control point
for the new segment.

X2 Optional Variant If the EditingType of the new


segment is msoEditingCorner,
this argument specifies the
horizontal distance (in points)
from the upper-left corner of the
document to the second control
point for the new segment. If
the EditingType of the new
segment is msoEditingAuto,
don't specify a value for this
argument.

Y2 Optional Variant If the EditingType of the new


segment is msoEditingCorner,
this argument specifies the
horizontal distance (in points)
from the upper-left corner of the
document to the second control
point for the new segment. If
the EditingType of the new
segment is msoEditingAuto,
don't specify a value for this
argument.

X3 Optional Variant If the EditingType of the new


segment is msoEditingCorner,
this argument specifies the
horizontal distance (in points)
from the upper-left corner of the
document to the second control
point for the new segment. If
the EditingType of the new
segment is msoEditingAuto,
don't specify a value for this
argument.

Y3 Optional Variant If the EditingType of the new


segment is msoEditingCorner,
this argument specifies the
horizontal distance (in points)
from the upper-left corner of the
document to the second control
point for the new segment. If
the EditingType of the new
segment is msoEditingAuto,
don't specify a value for this
argument.

Remarks
MsoSegmentType can be one of these MsoSegmentType constants.

msoSegmentLine

msoSegmentCurve

MsoEditingType can be one of these MsoEditingType constants.

msoEditingAuto

msoEditingCorner

Cannot
be msoEditingSmooth or msoEditingSymmetric If SegmentType is msoSegmentLine, Editi
ngType must be msoEditingAuto.

Example
This example adds a freeform with four segments to myDocument.
VBA
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

MsoSegmentType Enumeration
(Office)
Office 2013 and later

Other Versions

Specifies the type for a segment. Used with the Insert and AddNodes methods of
the FreeformBuilder object.

Name Value Description

msoSegmentCurve 1 Curve.

msoSegmentLine 0 Line.
MsoEditingType Enumeration
(Office)
Office 2013 and later

Other Versions

Specifies the editing type of a node.

Name Value Description

msoEditingAuto 0 Editing type is appropriate to the segments being


connected.

msoEditingCorner 1 Corner node.

msoEditingSmooth 2 Smooth node.

msoEditingSymmetric 3 Symmetric node.


FreeformBuilder.Application
Property (Excel)
Office 2013 and later

Other Versions

When used without an object qualifier, this property returns an Application object that represents
the Microsoft Excel application. When used with an object qualifier, this property returns
an Application object that represents the creator of the specified object (you can use this property
with an OLE Automation object to return the application of that object). Read-only.
Syntax
expression .Application
expression A variable that represents a FreeformBuilder object.
Example
This example displays a message about the application that created myObject.
VBA
Set myObject = ActiveWorkbook
If myObject.Application.Value = "Microsoft Excel" Then
MsgBox "This is an Excel Application object."
Else
MsgBox "This is not an Excel Application object."
End If
FreeformBuilder.ConvertToShape
Method (Excel)
Office 2013 and later

Other Versions

Creates a shape that has the geometric characteristics of the specified FreeformBuilder object.
Returns a Shape object that represents the new shape.
Syntax
expression .ConvertToShape
expression A variable that represents a FreeformBuilder object.
Return Value
Shape
Remarks
You must apply the AddNodes method to a FreeformBuilder object at least once before you use
the ConvertToShape method.
Example
This example adds a freeform with five vertices to myDocument.
VBA
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
AddShape Method
Office 2003

AddShape method as it applies to the CanvasShapes object.


Adds an AutoShape to a drawing canvas. Returns a Shape object that represents the AutoShape and
adds it to the CanvasShapes collection.
expression.AddShape(Type, Left, Top, Width, Height)
expression Required. An expression that returns a CanvasShapes object.
MsoAutoShapeType
MsoAutoShapeType can be one of these MsoAutoShapeType constants.

msoShapeFlowchartDirectAccessStorage

msoShapeFlowchartDocument

msoShapeFlowchartInternalStorage

msoShapeFlowchartManualInput

msoShapeFlowchartMerge

msoShapeFlowchartOffpageConnector

msoShapeFlowchartPredefinedProcess

msoShapeFlowchartProcess

msoShapeLeftBracket

msoShapeFlowchartConnector

msoShapeFlowchartData

msoShapeFlowchartDecision

msoShapeFlowchartDelay

msoShapeFlowchartDisplay

msoShapeFlowchartExtract
msoShapeFlowchartMagneticDisk

msoShapeFlowchartManualOperation

msoShapeFlowchartMultidocument

msoShapeFlowchartOr

msoShapeFlowchartPreparation

msoShapeFlowchartPunchedTape

msoShapeFlowchartSequentialAccessStorage

msoShapeFlowchartSort

msoShapeFlowchartStoredData

msoShapeFlowchartSummingJunction

msoShapeFlowchartTerminator

msoShapeFoldedCorner

msoShapeHeart

msoShapeHexagon

msoShapeHorizontalScroll

msoShapeIsoscelesTriangle

msoShapeLeftArrow

msoShapeLeftArrowCallout

msoShapeLeftBrace

msoShapeLeftRightArrow

msoShapeLeftRightArrowCallout

msoShapeLeftRightUpArrow
msoShapeLeftUpArrow

msoShapeLightningBolt

msoShapeLineCallout1

msoShapeLineCallout1AccentBar

msoShapeLineCallout1BorderandAccentBar

msoShapeLineCallout1NoBorder

msoShapeLineCallout2

msoShapeLineCallout2AccentBar

msoShapeLineCallout2BorderandAccentBar

msoShapeLineCallout2NoBorder

msoShapeLineCallout3

msoShapeLineCallout3AccentBar

msoShapeLineCallout3BorderandAccentBar

msoShapeLineCallout3NoBorder

msoShapeLineCallout4

msoShapeLineCallout4AccentBar

msoShapeLineCallout4BorderandAccentBar

msoShapeLineCallout4NoBorder

msoShapeMixed

msoShapeMoon

msoShapeNoSymbol

msoShapeNotchedRightArrow
msoShapeNotPrimitive

msoShapeOctagon

msoShapeOval

msoShapeOvalCallout

msoShapeParallelogram

msoShapePentagon

msoShapePlaque

msoShapeQuadArrow

msoShapeQuadArrowCallout

msoShapeRectangle

msoShapeRectangularCallout

msoShapeRegularPentagon

msoShapeRightArrow

msoShapeRightArrowCallout

msoShapeRightBrace

msoShapeRightBracket

msoShapeRightTriangle

msoShapeRoundedRectangle

msoShapeRoundedRectangularCallout

msoShapeSmileyFace

msoShapeStripedRightArrow

msoShapeSun
msoShapeTrapezoid

msoShapeUpArrow

msoShapeUpArrowCallout

msoShapeUpDownArrow

msoShapeUpDownArrowCallout

msoShapeUpRibbon

msoShapeUTurnArrow

msoShapeVerticalScroll

msoShapeWave

msoShape16pointStar

msoShape24pointStar

msoShape32pointStar

msoShape4pointStar

msoShape5pointStar

msoShape8pointStar

msoShapeActionButtonBackorPrevious

msoShapeActionButtonBeginning

msoShapeActionButtonCustom

msoShapeActionButtonDocument

msoShapeActionButtonEnd

msoShapeActionButtonForwardorNext

msoShapeActionButtonHelp
msoShapeActionButtonHome

msoShapeActionButtonInformation

msoShapeActionButtonMovie

msoShapeActionButtonReturn

msoShapeActionButtonSound

msoShapeArc

msoShapeBalloon

msoShapeBentArrow

msoShapeBentUpArrow

msoShapeBevel

msoShapeBlockArc

msoShapeCan

msoShapeChevron

msoShapeCircularArrow

msoShapeCloudCallout

msoShapeCross

msoShapeCube

msoShapeCurvedDownArrow

msoShapeCurvedDownRibbon

msoShapeCurvedLeftArrow

msoShapeCurvedRightArrow

msoShapeCurvedUpArrow
msoShapeCurvedUpRibbon

msoShapeDiamond

msoShapeDonut

msoShapeDoubleBrace

msoShapeDoubleBracket

msoShapeDoubleWave

msoShapeDownArrow

msoShapeDownArrowCallout

msoShapeDownRibbon

msoShapeExplosion1

msoShapeExplosion2

msoShapeFlowchartAlternateProcess

msoShapeFlowchartCard

msoShapeFlowchartCollate

Left Required Single. The position, measured in points, of the left edge of the AutoShape.
Top Required Single. The position, measured in points, of the top edge of the AutoShape.
Width Required Single. The width, measured in points, of the AutoShape.
Height Required Single. The height, measured in points, of the AutoShape.
AddShape method as it applies to the Shapes object.
Adds an AutoShape to a document. Returns a Shape object that represents the AutoShape and adds
it to the Shapes collection.
expression.AddShape(Type, Left, Top, Width, Height, Anchor)
expression Required. An expression that returns a Shapes object.
MsoAutoShapeType
MsoAutoShapeType can be one of these MsoAutoShapeType constants.

msoShapeFlowchartDirectAccessStorage

msoShapeFlowchartDocument
msoShapeFlowchartInternalStorage

msoShapeFlowchartManualInput

msoShapeFlowchartMerge

msoShapeFlowchartOffpageConnector

msoShapeFlowchartPredefinedProcess

msoShapeFlowchartProcess

msoShapeLeftBracket

msoShapeFlowchartConnector

msoShapeFlowchartData

msoShapeFlowchartDecision

msoShapeFlowchartDelay

msoShapeFlowchartDisplay

msoShapeFlowchartExtract

msoShapeFlowchartMagneticDisk

msoShapeFlowchartManualOperation

msoShapeFlowchartMultidocument

msoShapeFlowchartOr

msoShapeFlowchartPreparation

msoShapeFlowchartPunchedTape

msoShapeFlowchartSequentialAccessStorage

msoShapeFlowchartSort

msoShapeFlowchartStoredData
msoShapeFlowchartSummingJunction

msoShapeFlowchartTerminator

msoShapeFoldedCorner

msoShapeHeart

msoShapeHexagon

msoShapeHorizontalScroll

msoShapeIsoscelesTriangle

msoShapeLeftArrow

msoShapeLeftArrowCallout

msoShapeLeftBrace

msoShapeLeftRightArrow

msoShapeLeftRightArrowCallout

msoShapeLeftRightUpArrow

msoShapeLeftUpArrow

msoShapeLightningBolt

msoShapeLineCallout1

msoShapeLineCallout1AccentBar

msoShapeLineCallout1BorderandAccentBar

msoShapeLineCallout1NoBorder

msoShapeLineCallout2

msoShapeLineCallout2AccentBar

msoShapeLineCallout2BorderandAccentBar
msoShapeLineCallout2NoBorder

msoShapeLineCallout3

msoShapeLineCallout3AccentBar

msoShapeLineCallout3BorderandAccentBar

msoShapeLineCallout3NoBorder

msoShapeLineCallout4

msoShapeLineCallout4AccentBar

msoShapeLineCallout4BorderandAccentBar

msoShapeLineCallout4NoBorder

msoShapeMixed

msoShapeMoon

msoShapeNoSymbol

msoShapeNotchedRightArrow

msoShapeNotPrimitive

msoShapeOctagon

msoShapeOval

msoShapeOvalCallout

msoShapeParallelogram

msoShapePentagon

msoShapePlaque

msoShapeQuadArrow

msoShapeQuadArrowCallout
msoShapeRectangle

msoShapeRectangularCallout

msoShapeRegularPentagon

msoShapeRightArrow

msoShapeRightArrowCallout

msoShapeRightBrace

msoShapeRightBracket

msoShapeRightTriangle

msoShapeRoundedRectangle

msoShapeRoundedRectangularCallout

msoShapeSmileyFace

msoShapeStripedRightArrow

msoShapeSun

msoShapeTrapezoid

msoShapeUpArrow

msoShapeUpArrowCallout

msoShapeUpDownArrow

msoShapeUpDownArrowCallout

msoShapeUpRibbon

msoShapeUTurnArrow

msoShapeVerticalScroll

msoShapeWave
msoShape16pointStar

msoShape24pointStar

msoShape32pointStar

msoShape4pointStar

msoShape5pointStar

msoShape8pointStar

msoShapeActionButtonBackorPrevious

msoShapeActionButtonBeginning

msoShapeActionButtonCustom

msoShapeActionButtonDocument

msoShapeActionButtonEnd

msoShapeActionButtonForwardorNext

msoShapeActionButtonHelp

msoShapeActionButtonHome

msoShapeActionButtonInformation

msoShapeActionButtonMovie

msoShapeActionButtonReturn

msoShapeActionButtonSound

msoShapeArc

msoShapeBalloon

msoShapeBentArrow

msoShapeBentUpArrow
msoShapeBevel

msoShapeBlockArc

msoShapeCan

msoShapeChevron

msoShapeCircularArrow

msoShapeCloudCallout

msoShapeCross

msoShapeCube

msoShapeCurvedDownArrow

msoShapeCurvedDownRibbon

msoShapeCurvedLeftArrow

msoShapeCurvedRightArrow

msoShapeCurvedUpArrow

msoShapeCurvedUpRibbon

msoShapeDiamond

msoShapeDonut

msoShapeDoubleBrace

msoShapeDoubleBracket

msoShapeDoubleWave

msoShapeDownArrow

msoShapeDownArrowCallout

msoShapeDownRibbon
msoShapeExplosion1

msoShapeExplosion2

msoShapeFlowchartAlternateProcess

msoShapeFlowchartCard

msoShapeFlowchartCollate

Left Required Single. The position, measured in points, of the left edge of the AutoShape.
Top Required Single. The position, measured in points, of the top edge of the AutoShape.
Width Required Single. The width, measured in points, of the AutoShape.
Height Required Single. The height, measured in points, of the AutoShape.
Anchor Optional Variant. A Range object that represents the text to which the AutoShape is
bound. If Anchor is specified, the anchor is positioned at the beginning of the first paragraph in the
anchoring range. If this argument is omitted, the anchoring range is selected automatically and the
AutoShape is positioned relative to the top and left edges of the page.
Remarks
To change the type of an AutoShape that you've added, set the AutoShapeType property.
Example
As it applies to the CanvasShapes object.
This example creates a new canvas in the active document and adds a circle to the canvas.
Sub NewCanvasShape()
Dim shpCanvas As Shape
Dim shpCanvasShape As Shape

'Add a new drawing canvas to the active document


Set shpCanvas = ActiveDocument.Shapes.AddCanvas( _
Left:=100, Top:=75, Width:=150, Height:=200)
'Add a circle to the drawing canvas
Set shpCanvasShape = shpCanvas.CanvasItems.AddShape( _
Type:=msoShapeOval, Left:=25, Top:=25, _
Width:=150, Height:=150)
End Sub

As it applies to the Shapes object.


This example adds a red rectangle to a new document.
Sub NewShape()
Dim docNew As Document
'Create a new document and adds a shape
Set docNew = Documents.Add
docNew.Shapes.AddShape Type:=msoShapeRectangle, _
Left:=50, Top:=50, Width:=100, Height:=200
'Format the shape
docNew.Shapes(1).Fill.ForeColor _
.RGB = RGB(Red:=200, Green:=15, Blue:=95)
End Sub
Re: VBA code to draw a circle in the active cell
Maybe something like this:

Code:

Sub DrawCircleOnActiveCell()
ActiveSheet.Shapes.AddShape(msoShapeOval, 12, 6.75, 60, 23.25).Select
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Name = "myCircle"
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
With Selection.ShapeRange.Line
.Visible = msoTrue
.Weight = 2.25
End With
ActiveWindow.RangeSelection.Select
With ActiveSheet.Shapes("myCircle")
.Top = ActiveCell.Top
.Left = ActiveCell.Left
End With

End Sub

Re: VBA code to draw a circle in the active cell


I see Joe has already responded, but I submit this alternate method which uses the general
strategy you had, but forces the circle to be sized and centered based on the dimensions of
the activecell (and keeps the shape an actual circle)

Code:
Sub Add_Circle_in_ActiveCell()
t = ActiveCell.Top
l = ActiveCell.Left
h = ActiveCell.Height
w = ActiveCell.Width
min_dim = IIf(h > w, w, h) 'determine thinnest dimension so circle fits that
dimension and is centered correctly
v_center = t + h / 2 - min_dim / 2
h_center = l + w / 2 - min_dim / 2
ActiveSheet.Shapes.AddShape(msoShapeOval, h_center, v_center, min_dim,
min_dim).Select
Selection.ShapeRange.Fill.Visible = msoFalse
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
With Selection.ShapeRange.Line
.Visible = msoTrue
.Weight = 2.25
End With
End Sub

...or this one that doesn't make it a circle, but fits the oval to the total dimensions of the
activecell
Code:
Sub Add_Oval_in_ActiveCell()
t = ActiveCell.Top
l = ActiveCell.Left
h = ActiveCell.Height
w = ActiveCell.Width
ActiveSheet.Shapes.AddShape(msoShapeOval, l, t, w, h).Select
Selection.ShapeRange.Fill.Visible = msoFalse
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
With Selection.ShapeRange.Line
.Visible = msoTrue
.Weight = 2.25
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)


With Target
If IsNumeric(.Value) And .Value > 0 Then
Set TheCircle = ActiveSheet.Shapes.AddShape(msoShapeOval, .Left + .Width /
2 - .Value / 2, .Top + .Height / 2 - .Value / 2, .Value, .Value)
' Optional stuff:
' With TheCircle
' .LockAspectRatio = msoTrue
' With .Line
' .Weight = 3.5
' .ForeColor.SchemeColor = 10
' .BackColor.RGB = RGB(255, 255, 255)
' End With
' With .Fill
' .Solid
' .ForeColor.SchemeColor = 43
' .Transparency = 0.69
' End With
' End With
End If
End With
End Sub
up I am trying to add a shape at a specific cell location but cannot get the shape added
vote3do at the desired location for some reason. Below is the code I am using to add the
wn votefavorite
shape:

Cells(milestonerow, enddatecellmatch.Column).Activate

Dim cellleft As Single


Dim celltop As Single
Dim cellwidth As Single
Dim cellheight As Single

cellleft = Selection.Left
celltop = Selection.Top

ActiveSheet.Shapes.AddShape(msoShapeOval, cellleft, celltop, 4, 10).Select


I used variables to capture the left and top positions to check the values that were
being set in my code vs. the values I saw when adding the shape manually in the
active location while recording a macro. When I run my code, cellleft = 414.75 and
celltop = 51, but when I add the shape manually to the active cell location while
recording a macro, cellleft = 318.75 and celltop = 38.25. I have been
troubleshooting this for a while and have looked over a lot of existing questions
online about adding shapes, but I cannot figure this out. Any help would be greatly
appreciated.

The above code is working absolutely OK for me. Siddharth Rout Apr 16 '13 at 13:56

.Activate in first line doesn't necessary mean that it equals to Selection then... you need to check it. Or simply
change .Activate into .Select in first line. Kazimierz Jawor Apr 16 '13 at 14:04

1 I have the same problem. There is a little difference between .Cell.Left and the true position of a shape. This
"bug" occurs only on excel 2007. On excel 2003, the vba code works well. On 2010 i don't know. I try the
Debug.Print but i see no effect. user2747325 Sep 4 '13 at 14:30

Not working for me 2... on some sheets it is fine, in others, big offset from where it should be cyberponkJan 25
at 2:32

Are you using any zoom different than 100%? I found out there is a drawing error for shape positions when
using zoom. (tested on excel 2016) cyberponk Jan 25 at 2:52

add a comment

2 Answers
up This seems to be working for me. I added the debug statements at the end to
vote5do display whether the shape's .Top and .Left are equal to the
wn vote cell's .Top and .Left values.
For this, I had selected cell C2.
accepted

Sub addshapetocell()

Dim clLeft As Double


Dim clTop As Double
Dim clWidth As Double
Dim clHeight As Double

Dim cl As Range
Dim shpOval As Shape

Set cl = Range(Selection.Address) '<-- Range("C2")

clLeft = cl.Left
clTop = cl.Top
clHeight = cl.Height
clWidth = cl.Width

Set shpOval = ActiveSheet.Shapes.AddShape(msoShapeOval, clLeft, clTop, 4, 10)

Debug.Print shpOval .Left = clLeft


Debug.Print shpOval .Top = clTop

End Sub

I added your debug section in and both the shape and cell left and top points were the same so I have no idea
why it wasn't working. I saved the workbook, closed Excel, and then reopened it and then it worked fine so not
really sure what issue was, but thanks for answer. Casey Apr 20 '13 at 15:22

add a comment
up I found out this problem is caused by a bug that only happens when zoom level
vote0down is not 100%. The cell position is informed incorrectly in this case.
vote
A solution for this is to change zoom to 100%, set positions, then change back
to original zoom. You can use Application.ScreenUpdatinf to prevent flicker.

Dim oldZoom As Integer


oldZoom = Wn.Zoom
Application.ScreenUpdating = False
Wn.Zoom = 100 'Set zoom at 100% to avoid positioning errors

cellleft = Selection.Left
celltop = Selection.Top
ActiveSheet.Shapes.AddShape(msoShapeOval, cellleft, celltop, 4, 10).Select

Wn.Zoom = oldZoom 'Restore previous zoom


Application.ScreenUpdating = True
Reference Shape Made With BuildFreeForm
How do I select a shape I have just created with BuildFreeform function? It is not
convenient for me to reference the resultant shape as I have done below:

VB:
Public Sub DrawDoor(TileType As String, Xpos As Integer, Ypos As Integer)

With ActiveSheet.Shapes.BuildFreeform(msoEditingCorner, Xpos * 9 + 1, Ypos * 9 +


5)
.AddNodes msoSegmentCurve, msoEditingAuto, Xpos * 9 + 5, Ypos * 9 + 1
.AddNodes msoSegmentCurve, msoEditingAuto, Xpos * 9 + 9, Ypos * 9 + 5
.AddNodes msoSegmentLine, msoEditingAuto, Xpos * 9 + 9, Ypos * 9 + 10
.AddNodes msoSegmentLine, msoEditingAuto, Xpos * 9 + 1, Ypos * 9 + 10
.AddNodes msoSegmentLine, msoEditingAuto, Xpos * 9 + 1, Ypos * 9 + 5
.ConvertToShape
End With

Shapes(8).Fill.ForeColor.RGB = RGB(200, 90, 20)

End Sub

I want to give the shape a name, without having to use Shapes(8) at any stage. Is this
possible when making freeform shapes?

Regards,
Kjartan

Re: Select Shape Made With Buildfreeform


Like this?

VB:

Dim ffb As FreeformBuilder


Dim shp As Shape

Set ffb = ActiveSheet.Shapes.BuildFreeform(msoEditingCorner, Xpos * 9 + 1, Ypos * 9 +


5)
With ffb
.AddNodes msoSegmentCurve, msoEditingAuto, Xpos * 9 + 5, Ypos * 9 + 1
.AddNodes msoSegmentCurve, msoEditingAuto, Xpos * 9 + 9, Ypos * 9 + 5
.AddNodes msoSegmentLine, msoEditingAuto, Xpos * 9 + 9, Ypos * 9 + 10
.AddNodes msoSegmentLine, msoEditingAuto, Xpos * 9 + 1, Ypos * 9 + 10
.AddNodes msoSegmentLine, msoEditingAuto, Xpos * 9 + 1, Ypos * 9 + 5
End With

Set shp = ffb.ConvertToShape


shp.Fill.ForeColor.RGB = RGB(200, 90, 20)

Adding to shg's code, if you want to name the shape for future code to use then

VB:
Set shp = ffb.ConvertToShape
shp.Name = "myName"
Shapes("myName").Fill.ForeColor.RGB = RGB(200, 90, 20)
Font.NameFarEast Property
(Word)
Office 2013 and later

Other Versions

Returns or sets an East Asian font name. Read/write String.


Syntax
expression .NameFarEast
expression An expression that returns a Font object.
Remarks
In the U.S. English version of Microsoft Word, the default value of this property is Times New Roman.
This is the recommended way to return or set the font for Asian text in a document created in an
Asian version of Word.
Example
This example displays the East Asian font name that's applied to the selection.
VBA
MsgBox Selection.Font.NameFarEast
See also
Concepts
Font Object

Other resources
Font Object Members

You might also like