Class ShapeNode (Excel VBA)

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

The main procedure of class ShapeNode is ShapeNodes.Delete

Set

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

Dim strIndex As String: strIndex = 
Dim sns As ShapeNodes: Set sns = 
Dim shpnShapeNode As ShapeNode
Set shpnShapeNode = sns(Index:=strIndex)

The following procedures can be used to set variables of type ShapeNode: ShapeNodes.Item, Shape.Nodes and ShapeRange.Nodes

For Each

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

Dim shp As Shape: Set shp = 
Dim shpnNode As ShapeNode
For Each shpnNode In shp.Nodes
	
Next shpnNode

Methods

This is the main method of the ShapeNode class

ShapeNodes.Delete - Deletes the object.

Other Methods

ShapeNodes.Insert - Inserts a node into a freeform shape.

Sub InsertShapeNode() 
    ActiveSheet.Shapes(3).Select 
    With Selection.ShapeRange 
        If .Type = msoFreeform Then 
            .Nodes.Insert _ 
                Index:=3, SegmentType:=msoSegmentCurve, _ 
                EditingType:=msoEditingSymmetric, X1:=35, Y1:=100 
            .Fill.ForeColor.RGB = RGB(0, 0, 200) 
            .Fill.Visible = msoTrue 
        Else 
            MsgBox "This shape is not a Freeform object." 
        End If 
    End With 
End Sub

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.

Set myDocument = Worksheets(1) 
With myDocument.Shapes(3).Nodes 
    For n = 1 to .Count 
        If .Item(n).EditingType = msoEditingCorner Then 
            .SetEditingType n, msoEditingSmooth 
        End If 
    Next 
End With

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.

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

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.

Set myDocument = Worksheets(1) 
With myDocument.Shapes(3).Nodes 
    n = 1 
    While n <= .Count 
        If .Item(n).SegmentType = msoSegmentLine Then 
            .SetSegmentType n, msoSegmentCurve 
        End If 
        n = n + 1 
    Wend 
End With

Properties

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.

Set myDocument = Worksheets(1) 
With myDocument.Shapes(3).Nodes 
    For n = 1 to .Count 
        If .Item(n).EditingType = msoEditingCorner Then 
            .SetEditingType n, msoEditingSmooth 
        End If 
    Next 
End With

Parent returns the parent object for the specified object. Read-only.

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

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.

Set myDocument = Worksheets(1) 
With myDocument.Shapes(3).Nodes 
 n = 1 
 While n <= .Count 
 If .Item(n).SegmentType = msoSegmentLine Then 
 .SetSegmentType n, msoSegmentCurve 
 End If 
 n = n + 1 
 Wend 
End With

ShapeNodes.Count returns an Integer value that represents the number of objects in the collection.

ShapeNodes.Parent returns the parent object for the specified object. Read-only.