How to push an operation onto the Excel undo stack?

c#, excel, vsto

Solution

The solution I actually went with was the following:

- Save a copy of the clipboard state

- Clear the clipboard

- Generate the data I want in a tab/newline delimited format, push it to the clipboard

- Simulate a Ctrl+V operation to Excel

- Clear the clipboard

- Restore the original clipboard state

Obviously this is localized to cell manipulations, so you can't push arbitrary operations/callbacks to the undo stack. Also, I'm clearly violating principles around clipboard use in Windows, but if Microsoft exposed a better API for such things (hint), I wouldn't have to.

Additionally, I didn't go with the solution I described in the first comment on David Zemens' answer because I hit some security violations in our environment (i.e., injecting VBA code into a workbook is a no-no).

Anyways, thanks everybody!

Problem

I'm building a VSTO Excel add-in that manipulates the values of multiple cells. I would like to allow the user to undo and redo the changes created by the add-in via the standard Excel features. I prefer to avoid using VBA. Is this possible? If so, how? Another question: is it possible to examine the existing undo/redo stack?

Original source

Related problems