Previous Document Next Document

Object Model Reference : Classes : D : Document : Methods : Document.BeginCommandGroup


Document.BeginCommandGroup

Sub BeginCommandGroup([CommandName As String])

Description

Member of Document

The BeginCommandGroup method marks the start of a group of commands. By starting a command group, you define a sequence of document handling commands that you can undo in a single step.

 
The BeginCommandGroup and EndCommandGroup commands must be used with extreme caution. If an error occurs after BeginCommandGroup but before EndCommandGroup, and the macro is terminated, the undo stack of CorelDRAW for the current document becomes corrupt. You must ensure that EndCommandGroup is always issued after BeginCommandGroup. Proper error-trapping is strongly recommended.

Parameter
Description
CommandName
Specifies the name of the command. This parameter is optional.

VBA example 1

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
VBA example 2

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

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.