"undo" macro!?

G

Guest

Guest
Guys-

I have a macro that I perform, but I would like to create another macro to "undo" this macro! The reason is b/c once I run the original macro, there are instances in which I would like my spreadsheet to go back to the way it was before the macro, and the "undo" function is not an option in this case. So, I would like to create an "undo" macro to perform this function. Any ideas?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This could be tricky. One suggestion is save the workbook in a "temp" directory when you run it.

You could then seamlessly reload this by hitting an "undo" button or toolbar option.

_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-03-11 13:00
 
Upvote 0
Hi

Scripts by nature a fuzzy little nasty thinks in one sence they dont undo !

What you need to do is :
1 set reversal of you code IE return it to as was on another command button
2 place rthe reset undos in auto_Close to remake as you want.

Does this help...


BTW depend of what you do and what i guess..
 
Upvote 0
I didn't exactly follow that last post...I think I need a little more explanation (sorry!)
 
Upvote 0
Hello,

butt-ugly code, but I thought I would take a stab at it anyway. It's amateurish, but it works. (Maybe someone has better idea or can refine?) Please go easy on the tomatoes!

place in 'thisworkbook' object:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim TWbName$
TWbName = ThisWorkbook.Path & "" & Mid(ThisWorkbook.Name, 1, Len(ThisWorkbook.Name) - 4)
On Error Resume Next
Kill TWbName & ".xlu"
Kill TWbName & ".del"
End Sub

Place in a module:

Sub SetUndoPoint()
Dim TWbName$
TWbName = ThisWorkbook.Path & "" & Mid(ThisWorkbook.Name, 1, Len(ThisWorkbook.Name) - 4)
ThisWorkbook.SaveCopyAs TWbName & ".xlu"
End Sub


Sub UndoMacro()
Dim TWbName$
TWbName = ThisWorkbook.Path & "" & Mid(ThisWorkbook.Name, 1, Len(ThisWorkbook.Name) - 4)
Application.ScreenUpdating = False
Application.EnableEvents = True
ThisWorkbook.SaveAs TWbName & ".del"
Workbooks.Open TWbName & ".xlu"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs TWbName & ".xls"
Application.DisplayAlerts = True
Kill TWbName & ".xlu"
ThisWorkbook.Close False
End Sub

Then, just add this line to the first line of the macro you'd like to be able to undo:

SetUndoPoint

The UndoMacro macro can be assigned to a custom button or menu, then run to restore workbook before the macro was run.

Aloha!
This message was edited by ]-[ /-\ \/\/ /-\ | | /-\ |\| on 2002-03-12 04:22
 
Upvote 0
hey,

I like that code u just quoted. I wonder if that sort of an approach would help me with what I want with regards to the topic on saving work while u work - i.e. saving work automatically every 5 minutes in ANOTHER workbook perhaps in the temp folder so that I could retrieve something if it all crashes.

That way, I always have a backup without bothering to set one up :wink:

RET79
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top