Undo functionality w/ VBA?

  • Thread starter Thread starter Kevin T. Ryan
  • Start date Start date
K

Kevin T. Ryan

Hi all -

I was wondering if anyone knew of a way to save the state of an excel
workbook so that users could Ctrl-Z (i.e. undo) changes made by a VBA
procedure or macro? For example, if my macro simply bold-faced a
particular cell, Ctrl-Z would revert the formatting to whatever it was
before? Any thoughts would be appreciated. TIA,

Kevin
 
Kevin,

Running a VBA procedure clears Excel's undo buffer, effectively
disabling the Undo feature. The closest you can get is to create
a procedure that undoes your primary procedure, and use
Application.OnUndo to put that procedure in the undo buffer.
E.g.,

Sub AAAA()
Application.OnUndo "Undo This", "UndoProc"
End Sub

Sub UndoProc()
MsgBox "Undo code here"
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Kevin,

As Chip explained there isn't any built-in method. If you really need this
type of functionality, then one general approach might be to save a current
copy of the workbook before starting the VBA changes. If you need to revert
back, then close the current workbook and open the previously saved file.

Troy
 
Thanks guys, I'll probably try the "save-changes", re-open procedure
as it sounds a little easier to implement. Take care,

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top