Class ShapeNode (Excel VBA)

The class ShapeNode represents the geometry and the geometry-editing properties of the nodes in a user-defined freeform.

Item

To use a ShapeNode class variable it first needs to be instantiated, for example

Dim shpn as ShapeNode
Set shpn = ActiveChart.OLEObjects.ShapeRange.Nodes(Index:=1)

ShapeNode class variables can be set using the ShapeNodes.Item procedure.

For Each

Here is an example of processing the ShapeNode items in a collection.

Dim shpnNode As ShapeNode
For Each shpnNode In ActiveChart.OLEObjects.ShapeRange.Nodes
	
Next shpnNode

EditingType

If the specified node is a vertex, this property returns a value that indicates how changes made to the node affect the two segments connected to the node.

This property is read-only. Use the SetEditingType method to set the value of this property.

Dim metEditingType As Office.MsoEditingType
metEditingType = ActiveChart.OLEObjects.ShapeRange.Nodes(1).EditingType

Points

Returns the position of the specified node as a coordinate pair. Each coordinate is expressed in points. Read-only Variant.

This property is read-only. Use the SetPosition method to set the value of this property.

Set myDocument = Worksheets(1) 
With myDocument.Shapes(3).Nodes 
 pointsArray = .Item(2).Points 
 currXvalue = pointsArray(1, 1) 
 currYvalue = pointsArray(1, 2) 
 .SetPosition 2, currXvalue + 200, currYvalue + 300 
End With

SegmentType

Returns a value that indicates whether the segment associated with the specified node is straight or curved. If the specified node is a control point for a curved segment, this property returns msoSegmentCurve.

Use the SetSegmentType method to set the value of this property.

Dim mstSegmentType As Office.MsoSegmentType
mstSegmentType = ActiveChart.OLEObjects.ShapeRange.Nodes(1).SegmentType

ShapeNodes.Count

Returns an Integer value that represents the number of objects in the collection.

Dim lngCount As Long
lngCount = ActiveChart.OLEObjects.ShapeRange.Nodes.Count

ShapeNodes.Delete

Deletes the object.

Delete (Index)

Index: The index of the object to delete.

Dim lngIndex As Long: lngIndex = 
ActiveChart.OLEObjects.ShapeRange.Nodes.Delete Index:=lngIndex

ShapeNodes.Insert

Inserts a node into a freeform shape.

Insert (Index, SegmentType, EditingType, X1, Y1, X2, Y2, X3, Y3)

Dim lngIndex As Long: lngIndex = 
ActiveChart.OLEObjects.ShapeRange.Nodes.Insert Index:=lngIndex, SegmentType:=msoSegmentLine, EditingType:=msoEditingAuto, X1:=, Y1:=

Arguments

The following arguments are required:

Index (Long) - The number of the shape node after which to insert a new node.

SegmentType (Office.MsoSegmentType) - The segment type.

EditingType (Office.MsoEditingType) - The editing type.

X1 (Single) - If the EditingType of the new segment is msoEditingAuto, this argument specifies the horizontal distance, measured 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, measured in points, from the upper-left corner of the document to the first control point for the new segment.

Y1 (Single) - If the EditingType of the new segment is msoEditingAuto, this argument specifies the vertical distance, measured 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 vertical distance, measured in points, from the upper-left corner of the document to the first control point for the new segment.

Optional arguments

The following arguments are optional

X2 (Single) - If the EditingType of the new segment is msoEditingCorner, this argument specifies the horizontal distance, measured 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 (Single) - If the EditingType of the new segment is msoEditingCorner, this argument specifies the vertical distance, measured 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 (Single) - If the EditingType of the new segment is msoEditingCorner, this argument specifies the horizontal distance, measured in points, from the upper-left corner of the document to the end point of the new segment. If the EditingType of the new segment is msoEditingAuto, don't specify a value for this argument.

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

X2 (Single) - If the EditingType of the new segment is msoEditingCorner, this argument specifies the horizontal distance, measured 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 (Single) - If the EditingType of the new segment is msoEditingCorner, this argument specifies the vertical distance, measured 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 (Single) - If the EditingType of the new segment is msoEditingCorner, this argument specifies the horizontal distance, measured in points, from the upper-left corner of the document to the end point of the new segment. If the EditingType of the new segment is msoEditingAuto, don't specify a value for this argument.

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

ShapeNodes.Item

Returns a single object from a collection.

Item (Index)

Index: The name or index number for the object.

Dim shpn As ShapeNode
Set shpn = ActiveChart.OLEObjects.ShapeRange.Nodes(Index:=1)

ShapeNodes.SetEditingType

Sets the editing type of the node specified by Index. If the node is a control point for a curved segment, this method sets the editing type of the node adjacent to it that joins two segments. Note that, depending on the editing type, this method may affect the position of adjacent nodes.

SetEditingType (Index, EditingType)

Dim lngIndex As Long: lngIndex = 
ActiveChart.OLEObjects.ShapeRange.Nodes.SetEditingType Index:=lngIndex, EditingType:=msoEditingAuto

Arguments

The following arguments are required:

Index (Long) - The node whose editing type is to be set.

EditingType (Office.MsoEditingType) - The editing property of the vertex.

ShapeNodes.SetPosition

Sets the location of the node specified by Index. Note that, depending on the editing type of the node, this method may affect the position of adjacent nodes.

SetPosition (Index, X1, Y1)

Dim lngIndex As Long: lngIndex = 
ActiveChart.OLEObjects.ShapeRange.Nodes.SetPosition Index:=lngIndex, X1:=, Y1:=

Arguments

The following arguments are required:

Index (Long) - The node whose position is to be set.

X1 (Single) - The position (in points) of the new node relative to the upper-left corner of the document.

Y1 (Single) - The position (in points) of the new node relative to the upper-left corner of the document.

ShapeNodes.SetSegmentType

Sets the segment type of the segment that follows the node specified by Index. If the node is a control point for a curved segment, this method sets the segment type for that curve. Note that this may affect the total number of nodes by inserting or deleting adjacent nodes.

SetSegmentType (Index, SegmentType)

Dim lngIndex As Long: lngIndex = 
ActiveChart.OLEObjects.ShapeRange.Nodes.SetSegmentType Index:=lngIndex, SegmentType:=msoSegmentLine

Arguments

The following arguments are required:

Index (Long) - The node whose segment type is to be set.

SegmentType (Office.MsoSegmentType) - Specifies if the segment is straight or curved.