Excel 加载项表单在表单关闭时将 Excel 发送到后台

发布于 2024-12-04 21:52:42 字数 227 浏览 0 评论 0原文

我有一个可以弹出表单的 Excel 加载项。如果用户填写一些值并单击“应用”按钮,这些值将正确发送到基础工作表,并且弹出表单将关闭。但是,如果用户单击“取消”,则会弹出一个消息框,验证用户是否想要取消。单击“是”会导致弹出窗体关闭,但也会将 Excel 发送到先前活动的窗口后面 - 非常类似于按 Alt-Tab。这可不好啊!

有人对如何保持 Excel 领先地位有任何想法吗?

谢谢!

兰迪

I have an Excel Add-In that pops up a form. If the user fills in some values and clicks the "Apply" button, the values are correctly sent to the underlying worksheet and the pop-up form closes. If, however, the user clicks on "Cancel," a Messagebox pops-up verifying that the user wants to cancel. Clicking "Yes" causes the pop-up form to close, but also sends Excel behind the previously active window -- very much like pressing Alt-Tab. This is not good!

Does anybody have any notions about how to keep Excel on top?

Thanks!

Randy

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

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

发布评论

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

评论(2

破晓 2024-12-11 21:52:42

您可以将其放在消息框之后 ActiveWindow.ActivatePrevious
并测试

Debug.Print ActiveWindow.Caption
ActiveWindow.ActivatePrevious
Debug.Print ActiveWindow.Caption

You could put this in right after the message box ActiveWindow.ActivatePrevious
And test with

Debug.Print ActiveWindow.Caption
ActiveWindow.ActivatePrevious
Debug.Print ActiveWindow.Caption
可爱咩 2024-12-11 21:52:42

我寻找了 ActiveWindow/ActiveView 的各种变体,但找不到任何适用的内容。最后我绕过桑树丛想出了这个:

        IntPtr excelWindow = excelWindow = SpreadsheetApplicationFactoryBase.TheExcelApp.ExcelWin32Window.Handle;
        Win32.SetActiveWindow(excelWindow);

丑陋,但它有效。工厂是一个创建/返回 Excel 实例的小类。

我非常感谢您的意见。

兰迪

I looked for all sorts of variations on ActiveWindow/ActiveView but couldn't find anything applicable. Finally I went around the Mulberry bush to come up with this:

        IntPtr excelWindow = excelWindow = SpreadsheetApplicationFactoryBase.TheExcelApp.ExcelWin32Window.Handle;
        Win32.SetActiveWindow(excelWindow);

Ugly, but it works. The factory is a small class that creates/returns the Excel instance.

I very much appreciate the input.

Randy

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