BHoM / Excel_UI

GNU Lesser General Public License v3.0
5 stars 3 forks source link

Excel_Toolkit: Some undo functions disabled #136

Closed rwemay closed 1 year ago

rwemay commented 5 years ago

Description:

Undo doesn't work for some functions, for example add/remove columns/rows in a spreadsheet.

How to replicate:

Try to add/remove columns/rows in a spreadsheet with BHoM forumulae in and see if the undo function works.

Expected behaviour:

Test file(s):

awakeman commented 5 years ago

Are you experiencing this reliably or sporadically? I can't seem to reproduce myself.

awakeman commented 5 years ago

Found the issue: When we do things that modify the workbook, like selecting an item from globalsearch or the ribbon UI, we have to do so by queuing the change as a macro. According to the following answer on stack overflow:

there is not way to stop a worksheet-changing macro from clearing the undo stack.

https://stackoverflow.com/questions/7798575/undo-history-button-clear-after-run-macro-excel

As far as I have been able to tell you have to have this work run from a macro context because it is making changes to the sheet but I will check this to be certain. If that is the case we'll probably need to create our own Undo stack and override that of excel itself, no doubt this will be fraught with complexity to make it behave exactly as excel does normally.

adecler commented 4 years ago

After looking into this, I confirm this is related to calling QueueAsMacro. Some of those calls can be removed but it seems difficult to find a way around using macros. The undo stack is cleared when

This problem is not due to Excel DNA and is part of Excel: when a macro is ran, the undo stack is cleared since macros can make large scale changes to multiple spreadsheets so an undo there would be a bit complicated (well, still possible but it looks like Microsoft didn't want to bother).

I don't want to have our own undo stack as it would potentially affect the normal usage of Excel (and would also be quite painful to make sure we cover everything). So I can only think of two possibilities:

Since it looks like solving this is going to require a decent amount of investigation and time, I will put this on hold for this quarter unless I run out of things to do.

adecler commented 3 years ago

I had a final look at this today.

adecler commented 1 year ago

Closing as parked for a few years