Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel add-in with seamless Undo: possible?

I am considering implementing an Excel add-in using COM (not VBA) that will manipulate data in the worksheet.

I am going to need this add-in to seamlessly integrate with the Undo stack. More specifically:

  1. Any changes this add-in makes to the data need to be undoable by the user (through the standard Undo action)
  2. The items on the Undo stack before the add-in action takes place need to be preserved

In my (albeit perfunctory) research so far, it is unclear whether or not Excel can allow for this. If it does not, this is a showstopper, and the add-in will have no value.

My question: is it possible? This is more of a "yes or no" question than a "how" question, as I need to know if I am embarking on a wild goose chase or not. However, any pointers on how it can be done would be a bonus.

like image 934
kes Avatar asked Jun 22 '11 16:06

kes


2 Answers

Seems like it is not possible after all.

The Application.OnUndo method clears the current undo stack and places itself on top.
There doesn't seem to be anything else related to customizing undo.

It is possible.

Application.OnUndo registers an undo sub for the currently executing sub:

sub ImMakingChanges()
  cells(1,1).interior.color = vbyellow
  application.onundo "Undo the stupid color", "RemoveMyStupidChanges"
end sub

sub RemoveMyStupidChanges()
  cells(1,1).interior.colorindex = xlnone
end sub

Obviously, saving a previous state in the wild is generally a nightmare. But here you go.

Also, your undo sub will need to be visible to the general public so that Excel can find and call it.

like image 129
GSerg Avatar answered Sep 25 '22 02:09

GSerg


Apparently, this is not possible and there are no plans to support it even in Office 2013, as per the response by an MSFT employee on this thread.

like image 23
Ishan De Silva Avatar answered Sep 24 '22 02:09

Ishan De Silva