具有无缝撤消功能的 Excel 加载项:可能吗?

发布于 2024-11-16 19:43:04 字数 365 浏览 4 评论 0原文

我正在考虑使用 COM(而不是 VBA)实现一个 Excel 加载项,该加载项将操作工作表中的数据。

我将需要此插件与撤消堆栈无缝集成。 更具体地说:

  1. 此加载项对数据所做的任何更改都需要由用户撤消(通过标准撤消操作)
  2. 在加载项操作发生之前撤消堆栈上的项目需要保留

在我的(尽管是敷衍了事)中)到目前为止的研究,尚不清楚 Excel 是否允许这样做。如果没有,这就是一个阻碍,并且该加载项将没有任何价值。

我的问题:可能吗?这更像是一个“是或否”的问题,而不是一个“如何”的问题,因为我需要知道我是否正在开始徒劳的追逐。然而,任何关于如何做到这一点的指示都将是一个额外的好处。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

祁梦 2024-11-23 19:43:04

看来终究是不可能了。

Application.OnUndo 方法清除当前撤消堆栈并将其自身置于顶部。
似乎没有任何其他与自定义撤消相关的内容。

这是可能的。

Application.OnUndo 为当前正在执行的子程序注册一个撤消子程序:

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

显然,在野外保存先前的状态通常是恶梦。但你走了。

此外,您的撤消子项需要对公众可见,以便 Excel 可以找到并调用它。

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.

够运 2024-11-23 19:43:04

显然,这是不可能的,而且根据 MSFT 员工对此的回应,即使在 Office 2013 中也没有计划支持它 线程

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.

梦里寻她 2024-11-23 19:43:04

看起来毕竟是可能的

这是可以完成的,但是您必须编写一个非常复杂的撤消处理程序。
这是一个可以准确告诉您的链接
如何:http://www.jkp-ads.com/Articles/UndoWithVBA01.asp

幸运的是,该链接有完整的源代码,而且看起来很可靠,所以你应该不会有任何问题。
我很高兴听到这如何/是否对您有用。

PS:这是荷兰语的相同链接:http://www .jkp-ads.com/Articles/UndoWithVBA01NL.asp

Seems like it is possible after all

This can be done, but you'll have to write a pretty involved Undo handler.
Here's a link that well tell you exactly
how: http://www.jkp-ads.com/Articles/UndoWithVBA01.asp

Fortunatly the link has full sourcecode and it looks ironclad so you should have no problems.
I'll be happy to hear how/if this worked for you.

PS: here's the same link in Dutch: http://www.jkp-ads.com/Articles/UndoWithVBA01NL.asp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文