Is it possible to undo a macro
Also, a messagebox saying perhaps "This will take some time, please don't press 'Submit' again"? Show 2 more comments. Active Oldest Votes. Here are two very easy things I can suggest: 1 Have the macro save the workbook before any changes are made, but not save the workbook after the changes have been made.
The first option requires the least amount of code, just: ThisWorkbook. Save before letting the macro do whatever the macro does. I frequently use this method when testing macros. The second option is a little more complex, but not much: ThisWorkbook.
Worksheets "YourWorksheet". If necessary, you can reactivate the original worksheet like this: ThisWorkbook. Worksheets "OriginalWorksheet". Activate I hope that helps! Improve this answer. SeanW SeanW 4 4 silver badges 9 9 bronze badges. Thanks a lot for the tip. I used ActiveWorkbook. Save instead since my macro was in a different workbook from the one it was destroying.
Add a comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Humans of IT. Green Tech. MVP Award Program. Video Hub Azure. Microsoft Business. Microsoft Enterprise. Browse All Community Hubs. Turn on suggestions. Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type. Showing results for. Show only Search instead for. Did you mean:. Sign In. Occasional Visitor.
Hi There I've created a macro that copy some lines and delete values manually entered. Be very careful what you write and prompt for any action that can not be undone. The undo button is also unavailable after the macro is run.
You can use application. Name ActiveWorkbook. Re: Undoing a macro That would seem to fall apart if the macro contained a Save command. And really it's no different than saving the file just before you run your macro, then closing without saving changes if you don't like the results.
Re: Undoing a macro Ed, you are absolutely right, but if it doesn't contain a save command, it is an alternative to recover the file.
Harald Staff. Re: Undoing a macro Hi Greg You are assuming that the macro is simply doing things to 'the' file. A single macro can delete gigs of files from a hard drive, mess up the registry, refurnish the desktop, corrupt a few databases, email lots of nigerian spam, you name it.