Shape Object Descargas de Internet
Shape Object Descargas de Internet
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.
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
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
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
msoTextOrientationDownward 3 Downward.
msoTextOrientationHorizontal 1 Horizontal.
msoTextOrientationUpward 2 Upward.
msoTextOrientationVertical 5 Vertical.
msoFontAlignCenter 2 Specifies that the font is aligned to the center of 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
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
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
Remarks
MsoSegmentType can be one of these MsoSegmentType constants.
msoSegmentLine
msoSegmentCurve
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.
msoSegmentCurve 1 Curve.
msoSegmentLine 0 Line.
MsoEditingType Enumeration
(Office)
Office 2013 and later
Other Versions
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
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
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
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
Cells(milestonerow, enddatecellmatch.Column).Activate
cellleft = Selection.Left
celltop = Selection.Top
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 cl As Range
Dim shpOval As Shape
clLeft = cl.Left
clTop = cl.Top
clHeight = cl.Height
clWidth = cl.Width
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.
cellleft = Selection.Left
celltop = Selection.Top
ActiveSheet.Shapes.AddShape(msoShapeOval, cellleft, celltop, 4, 10).Select
VB:
Public Sub DrawDoor(TileType As String, Xpos As Integer, Ypos As Integer)
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
VB:
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
Other resources
Font Object Members