Why can't VBA module actions be reversed? i.e., Ctrl+Z'ed

707 Views Asked by At

For the past several months I've been writing VBA scripts, and have noticed that, if I write a module that acts upon an Excel workbook/sheet, I'm not able to Ctrl+Z these actions. This, from what I've noticed, applies to any and every action that's performed by the module.

A simple example would be:

Sub test()
  Cells(1,1) = "Hello World"
End Sub

Why can't module actions be "reversed"? i.e., undone through Ctrl+Z, or, by utilizing the 'undo' arrow.

P.S. I think this behavior might also apply to any module action within any MS application, though, I could easily be wrong.

1

There are 1 best solutions below

0
On BEST ANSWER

No they can't be reversed but you can use my method:

You could save your workbook (ActiveWorkbook.Save) at beginning of each macros then if you want to undo:

Const pathToTheFile as String = "C:\Users\VbaProject\"
Sub Undo()

    wb = ActiveWorkbook.Name

    Workbooks(wb).Close savechanges:=False
    Workbooks.Open Filename:=pathToTheFile & wb

End Sub

You can even bind it to a shortcut...