如何在Excel-Vba中以编程方式编写“撤消"功能的代码? [英] How to programmatically code an 'undo' function in Excel-Vba?

查看:1176
本文介绍了如何在Excel-Vba中以编程方式编写“撤消"功能的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否仍然可以将撤消功能编码到类似于Excel自己的撤消功能的CommandButton上?

Is there anyway to code an undo function onto a CommandButton similar to the Excel's very own undo function?

或可以调用Ctrl-Z快捷键的功能.

Or a function which is capable of calling Ctrl-Z shortcut key.

推荐答案

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

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

这篇关于如何在Excel-Vba中以编程方式编写“撤消"功能的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆