且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Excel-Vba中以编程方式编写“撤消"功能的代码?

更新时间:2023-11-30 14:38:52

将命令按钮添加到工作表并为其分配以下宏:

Add the command button to the worksheet and assign the following macro to it:

Sub UndoLastAction()

    With Application
        .EnableEvents = False
        .Undo
        .EnableEvents = True
    End With

End Sub

它只能撤消用户执行的最后一项操作,而不能撤消VBA命令.

It can only undo the last action taken by the user and cannot undo VBA commands.

如果需要进一步的撤消功能,请参见:

If you need further undo capabilities see:

使用Excel VBA撤消-JKP