Class ShapeNodes (Word VBA)
A collection of all the ShapeNode objects in the specified freeform. Each ShapeNode object represents either a node between segments in a freeform or a control point for a curved segment of a freeform. To use a ShapeNodes class variable it first needs to be instantiated, for example
Count
Returns a Long that represents the number of shape nodes in the collection.
Dim sns As ShapeNodes: Set sns =
Dim lngCount As Long
lngCount = sns.Count
Delete
Deletes the specified shape node.
Delete (Index)
Index: The number within the collection of shape nodes of the shape node to delete.
Dim lngIndex As Long: lngIndex =
Dim sns As ShapeNodes: Set sns =
sns.Delete Index:=lngIndex
Insert
Inserts a node into a freeform shape.
Insert (Index, SegmentType, EditingType, X1, Y1, X2, Y2, X3, Y3)
Sub InsertShapeNode()
ActiveDocument.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
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 type of line that connects the inserted node to the neighboring nodes.
EditingType (Office.MsoEditingType) - The editing property of the inserted node.
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 starting 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 starting 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 ending 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 ending point of the new segment. If the EditingType of the new segment is msoEditingAuto, don't specify a value for this argument.
Item
Returns an individual ShapeNode object in a collection.
Item (Index)
Index: The individual object to be returned. Can be a Long indicating the ordinal position of the individual object.
Dim sns As ShapeNodes: Set sns =
Dim shpn As ShapeNode
Set shpn = sns(Index:=1)
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. Depending on the editing type, this method may affect the position of adjacent nodes.
SetEditingType (Index, EditingType)
Dim lngLoop As lngLoop
With ActiveDocument.Shapes(3).Nodes
For lngLoop = 1 to .Count
If .Item(lngLoop).EditingType = msoEditingCorner Then
.SetEditingType lngLoop, msoEditingSmooth
End If
Next lngLoop
End With
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.
SetPosition
Sets the location of the node specified by Index.
Depending on the editing type of the node, this method may affect the position of adjacent nodes.
With ActiveDocument.Shapes(3).Nodes
pointsArray = .Item(2).Points
currXvalue = pointsArray(1, 1)
currYvalue = pointsArray(1, 2)
.SetPosition 2, currXvalue + 200, currYvalue + 300
End With
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
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 lngLoop As Long
With ActiveDocument.Shapes(3).Nodes
lngLoop = 1
While lngLoop <= .Count
If .Item(lngLoop).SegmentType = msoSegmentLine Then
.SetSegmentType lngLoop, msoSegmentCurve
End If
lngLoop = lngLoop + 1
Wend
End With
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.