如何在 Excel-Vba 中以编程方式编写“撤消”功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7004754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to programmatically code an 'undo' function in Excel-Vba?
提问by Vivian
Is there anyway to code an undo function onto a CommandButton similar to the Excel's very own undo function?
无论如何,是否可以将撤消功能编码到类似于 Excel 自己的撤消功能的 CommandButton 上?
Or a function which is capable of calling Ctrl-Z shortcut key.
或者可以调用 Ctrl-Z 快捷键的函数。
回答by Reafidy
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
It can only undo the last action taken by the user and cannot undo VBA commands.
它只能撤消用户上次执行的操作,不能撤消 VBA 命令。
EDIT: If you need further undo capabilities see:
编辑:如果您需要进一步的撤消功能,请参阅: