"ThisWorkbook.Close";导致Excel崩溃 [英] "ThisWorkbook.Close" Causes excel to crash

查看:451
本文介绍了"ThisWorkbook.Close";导致Excel崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量的excel文件,它们的工作原理几乎像一个程序,它们可以在多台计算机上运行(具有不同版本的Windows),最近我有这个 bad 问题,当用户按下 我的关闭按钮 (实际上是与宏相关联的图片)时,代码会调用:

I have a large collection of excel files that work almost like a program, and they run on multiple computers (with different versions of windows), and as of latelly I have this bad problem, when the user presses my close button(actually a picture I associate a macro with), with the code calls:

ThisWorkbook.Close savechanges:=True

这会导致4台受支持的计算机中的2台崩溃(Windows XP = OK,Windows 10 = OK 1不良,Windows 8 = BAD).

It causes 2 of the 4 supported computers to crach EXCEL (Windows XP = OK, Windows 10 = OK 1 BAD OTHER, Windows 8 = BAD).

我已将事件隔离到此特定代码行(仅通过关闭按钮制作了一张1张excel文件,但仍然崩溃) 我已经注意到,如果不是唯一打开excel文件,有时它不会崩溃(也许问题在于关闭excel本身)

I have isolated the incident to this particular line of code (made a 1 sheet excel file with just a close button, and it still crashes) I have noted that if the excel file isn't the only one open, sometimes it doesn't crash (maybe the problem is with closing excel itself)

我所做的是将2条语句分开,因此(如果)崩溃时,它已经保存了:

What I have done is separeted the 2 statements so if (when) it crashes it's already saved:

ThisWorkbook.Save
ThisWorkbook.Close

任何人都可以点亮一些灯光吗?我真的迷路了.我尝试了所有可以想到的替代方法(activeworkbook ...)

Can anyone shed some lights? I'm really lost. I tried all the alternatives I could think off (activeworkbook...)

Tl; dr: "ThisWorkbook.Close" 导致excel崩溃

Tl;dr: "ThisWorkbook.Close" Causes excel to crash

推荐答案

这是Microsoft Excel中的标准错误.不知道Microsoft是否有任何修复程序.但是,有解决方法可以解决此问题.

This is a standard bug in Microsoft Excel. Not sure if Microsoft has any fix. However, there are workarounds to overcome this issue.

当单击事件触发关闭"事件但与选择更改"之类的其他事件配合正常时,会发生此问题.要解决此问题,您可以尝试以下方法:

This issue occurs when "Close" event is triggered from a click event but works fine with other event like "Selection Change". To tackle this issue, you may try this one:

在按钮的click事件中添加以下代码:

Add the following code in the click event of the button:

Private Sub CloseButton_Click()
    Cancel = True
    Application.OnTime Now, "Close_Xls"
End Sub

在标准模块中,添加以下代码

In a standard module, add the following code

Sub Close_Xls()
   ThisWorkbook.Close  savechanges:=True
End Sub

对我有用.让我知道是否有帮助

It works for me. Let me know if it is helpful

这篇关于"ThisWorkbook.Close";导致Excel崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆