Class UndoRecord (Word VBA)

Provides an entry point into the undo stack.

Set

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

Dim urd as UndoRecord
Set urd = Application.UndoRecord

UndoRecord class variables can be set using the Application.UndoRecord procedure.

CustomRecordLevel

Returns a Long that specifies the number of custom undo action calls that are currently active.

If no custom undo action is active, this property is set to 0.

Dim objUndo As UndoRecord 
 
Sub MyFunction() 
 Set objUndo = Application.UndoRecord 
 
 ' Verify that a custom undo record is already being recorded, and if not, start one 
 If objUndo.IsRecordingCustomRecord = False Then 
 objUndo.StartCustomRecord("New Undo Record") 
 End If 
 ' Add some actions here. 
 objUndo.EndCustomRecord 
 
 ' Verify that any custom undo action calls are currently active. 
 If objUndo.CustomRecordLevel > 0 Then 
 Debug.Print "An undo record call was not closed!" 
 End If 
End Sub

CustomRecordName

Returns a String that specifies the entry that appears on the undo stack when all custom undo actions have completed.

If custom undo records are nested within other custom undo records, this property specifies what string appears on the undo stack after all custom undo actions have completed. If multiple calls to the StartCustomRecord method are nested, the string specified by the first call will be returned by this property. If no action is active, the property returns an empty string.

Sub WalkUndoRecordStack()
Dim objUndo As UndoRecord
 
'Create UndoRecord object
Set objUndo = Application.UndoRecord
 
'Begin first custom record
objUndo.StartCustomRecord ("First call")
    'Begin nested second custom record
    objUndo.StartCustomRecord ("Second call")
        'Begin nested third undo record
        objUndo.StartCustomRecord ("Third call")
            'Message for the third call is written first to the document
            Me.Content.InsertAfter "Third call. "
            'End third custom record
        objUndo.EndCustomRecord
        'Message for the second call is written second to the document
        Me.Content.InsertAfter "Second call. "
    'End second custom record
    objUndo.EndCustomRecord
    'Message for first call is written third to the document
    Me.Content.InsertAfter "First call. "
'End first custom record
objUndo.EndCustomRecord

Set objUndo = Nothing
End Sub

EndCustomRecord

Completes the creation of a custom undo record.

You use the UndoRecord.StartCustomRecord to initiate the creation of a custom undo record. To complete the creation of a custom undo record, you use the EndCustomRecord method.

Sub TestUndo() 
Dim objUndo As UndoRecord 
 
Set objUndo = Application.UndoRecord 
objUndo.StartCustomRecord ("My Custom Undo") 
    'Add some actions here 
objUndo.EndCustomRecord 
     
End Sub

IsRecordingCustomRecord

Returns a Boolean that specifies whether a custom undo action is being recorded.

Dim objUndo as UndoRecord 
Set objUndo = Application.UndoRecord 
 
If objUndo.IsRecordingCustomRecord = False Then 
objUndo.StartCustomRecord ("My Custom Undo") 
End If 
'Custom undo actions here 
objUndo.EndCustomRecord 

Parent

Returns an object that represents the parent object of the specified UndoRecord object.

Dim objParent As Object
Set objParent = Application.UndoRecord.Parent

StartCustomRecord

Initiates the creation of a custom undo record.

StartCustomRecord begins the creation of a custom undo record, which records all actions done to the application while it is active under a record defined by Name.

Syntax : expression.StartCustomRecord (Name)

Name: Specifies the name of the custom undo record. This string is limited to 64 characters. If a longer string is supplied, the string is truncated to 64 characters.

Sub TestUndo() 
Dim objUndo As UndoRecord 
 
Set objUndo = Application.UndoRecord 
objUndo.StartCustomRecord ("My Custom Undo") 
    'Add some actions here 
objUndo.EndCustomRecord 
     
End Sub