Examples:
The following VBA example creates a flower. After the macro finishes, its result can be undone in one step; the Edit menu displays an Undo Flower item.
Sub Test()
Const Leaves As Long = 30
Const Radius As Double = 2
Dim stp As Double
Dim i As Long
Dim d As Document
Dim s As Shape
stp = 360 / Leaves
Set d = ActiveDocument
d.DrawingOriginX = 0
d.DrawingOriginY = 0
d.BeginCommandGroup "Flower"
Set s = d.ActiveLayer.CreateEllipse2(0, 0, Radius)
s.Fill.UniformColor.RGBAssign 100, 50, 50
Set s = d.ActiveLayer.CreateEllipse2(Radius + 0.5, 0, 0.5, 0.25)
s.Fill.UniformColor.RGBAssign 255, 255, 0
s.RotationCenterX = 0
s.RotationCenterY = 0
d.ApplyToDuplicate = True
For i = 1 To Leaves - 1
s.Rotate i * stp
Next i
d.EndCommandGroup
End Sub
You must ensure that EndCommandGroup is always issued after BeginCommandGroup. Proper error-trapping, such as in the following VBA example, is strongly recommended.
Sub Test()
ActiveDocument.BeginCommandGroup "My Command"
On Error Goto ErrHandler
' Some commands go here
ExitSub:
ActiveDocument.EndCommandGroup
Exit Sub
ErrHandler:
MsgBox "Error occured: " & Err.Description
Resume ExitSub
End Sub