Building Undo Into an Excel VBA Macro

前端 未结 3 376
[愿得一人]
[愿得一人] 2020-12-01 04:05

Excel macros do not seem to allow the use of \"undo\" after running them. Is there any way to bake undo functionality into a VBA macro in Excel?

3条回答
  •  佛祖请我去吃肉
    2020-12-01 04:41

    Excel VBA has the Application.OnUndo function to handle this:

    Public Sub DoSomething
    
        ... do stuff here
    
        Application.OnUndo "Undo something", "UnDoSomething"
    End Sub
    
    Public Sub UnDoSomething
    
        ... reverse the action here
    
    End Sub

提交回复
热议问题