Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo Macros

Status
Not open for further replies.

Dan15

Technical User
Dec 23, 2002
66
US
Is there code to set up an "undo" button for Macro functions? Excel's undo button does not apply after running macros. Or at least, I don't know how to apply it.

Thanks-

-Dan
 
Dan,

I believe you're right - that there isn't a "macro undo".

However, I'd suggest the following should work "almost" as well...

1) Create a subroutine for saving the file.

2) Insert this subroutine before each "critical" point in your various routines.

3) Insert your own "undo button" - that simply retrieves the saved file.

I hope this can be a useful alternative. :) Please advise as to how it fits.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
There is a macro undo provision within Excel VBA, but not a particularly useful one without a lot of extra work:

application.onundo "Undo Cap Macro","UndoCapMacro"

will set the text of the edit-undo menu item to "Undo Cap Macro", and will run the sub "UndoCapMacro" when the menu item is chosen. However, it is still up to the programmer to actually implement the Undo. One option might be, as Dale suggested, to save a copy of the workbook, and retrieve it when the undo macro is called. In certain other cases, where the action of a macro is limited to a particular part of a workbook, it may make sense to copy just that part of the workbook to a temporary location (on a worksheet inside personal.xls or inside your add-in), and restore from that location.
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top