CanRedo Property

Applies To

Frame control, Page object, UserForm object.

Description

Indicates whether the most recent Undo can be reversed.

Syntax

object.CanRedo

The CanRedo property syntax has these parts:

Part

Description

object

Required. A valid object.


Return Values

The CanRedo property return values are:

Value

Description

True

The most recent Undo can be reversed.

False

The most recent Undo is irreversible.


Remarks

CanRedo is read-only.

To Redo an action means to reverse an Undo; it does not necessarily mean to repeat the last user action.

The following user actions illustrate using Undo and Redo:

  1. Change the setting of an option button.
  2. Enter text into a text box.
  3. Click Undo. The text disappears from the text box.
  4. Click Undo. The option button reverts to its previous setting.
  5. Click Redo. The value of the option button changes.
  6. Click Redo. The text reappears in the text box.
See Also

CanUndo property, RedoAction method, UndoAction method.

Example

The following example demonstrates how to undo or redo text editing within a text box or within the text area of a ComboBox. This sample checks whether an undo or redo operation can occur and then performs the appropriate action. The sample uses the CanUndo and CanRedo properties, and the UndoAction and RedoAction methods.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A TextBox named TextBox1.
  • A ComboBox named ComboBox1.
  • Two CommandButton controls named CommandButton1 and CommandButton2.
    Private Sub CommandButton1_Click()
        If UserForm1.CanUndo = True Then
            UserForm1.UndoAction
            MsgBox "Undid IT"
        Else
            MsgBox "No undo performed."
        End If
    End Sub
    
    Private Sub CommandButton2_Click()
        If UserForm1.CanRedo = True Then
            UserForm1.RedoAction
            MsgBox "Redid IT"
        Else
            MsgBox "No redo performed."
        End If
    End Sub
    
    Private Sub UserForm_Initialize()
        TextBox1.Text = "Type your text here."
        
        ComboBox1.ColumnCount = 3
        ComboBox1.AddItem "Choice 1, column 1"
        ComboBox1.List(0, 1) = "Choice 1, column 2"
        ComboBox1.List(0, 2) = "Choice 1, column 3"
    
        CommandButton1.Caption = "Undo"
        CommandButton2.Caption = "Redo"
    End Sub