PDA

View Full Version : Undo option



sasa
05-17-2008, 08:20 AM
Hi All,
is it possible to add some lines of code whatever macro the way it can also work as a sort of UNDO option and allow me to reverse back at the time just before I have launch it?

Thanks in advance

sasa

Bob Phillips
05-17-2008, 08:30 AM
Code wipes the UNDO stack, so you would somehow save all the changes yourself, them re-apply. Not trivial.

sasa
05-17-2008, 09:00 AM
I see. But I think this way is very expensive, a lot of saved data....
Thank you again

sasa

Aussiebear
05-17-2008, 03:20 PM
Normally when you execute a macro its because the User believes that certain conditions have been met or that it is triggered by particular condition/s on the sheet.

However if you are unsure, that the conditions are right, yet you still feel you need to execute a macro... then you might try saving the file first. This way if the macro does something that then proves unsuitable, close the active book without saving changes.

Simon Lloyd
05-18-2008, 12:52 AM
You have 2 options here:
1. Create a worksheet and macro to track changes made to the workbook you will then be able to create a macro to reverse these changes
2. Create a macro that reverses the effect of the one you ran and call it MyUnDoMacro, then at the bottom of your original macro add this line
Application.OnUndo "Undo My Macro", "MyUnDoMacro"the Undo My Macro is what the user would see and the latter part calls the macro, now after your macro has run you just click on the undo as you would normally and hey presto macro reversed!

sasa
05-18-2008, 03:49 AM
It is not possible copy the sheet of interest, make the changes, and then delete (http://www.ozgrid.com/forum/autolink.php?id=26&script=showthread&forumid=8) the copied sheet when one is sure of the changes or restore it if it is not so, maybe with a click on a icon on toolbar ?

sasa

Bob Phillips
05-18-2008, 04:09 AM
Yes that would work if the changes are all about a single sheet. You could copy it, hide it, and just copy it back if required.