简体   繁体   English

“ThisWorkbook.Close”导致excel崩溃

[英]“ThisWorkbook.Close” Causes excel to crash

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:我有一大堆 excel 文件,它们几乎像程序一样工作,它们可以在多台计算机上运行(使用不同版本的 Windows),最近我遇到了这个严重的问题,当用户按下我的关闭按钮(实际上是一张图片)我将宏与) 关联起来,代码调用:

ThisWorkbook.Close savechanges:=True

It causes 2 of the 4 supported computers to crach EXCEL (Windows XP = OK, Windows 10 = OK 1 BAD OTHER, Windows 8 = BAD).它会导致 4 台支持的计算机中的 2 台崩溃 EXCEL(Windows XP = OK,Windows 10 = OK 1 BAD OTHER,Windows 8 = BAD)。

在此处输入图片说明

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)我已将此事件与这一特定代码行隔离开来(仅用一个关闭按钮制作了一个 1 张 excel 文件,但它仍然崩溃)我注意到,如果 excel 文件不是唯一打开的文件,有时它不会崩溃(也许问题在于关闭 excel 本身)

What I have done is separeted the 2 statements so if (when) it crashes it's already saved:我所做的是将 2 个语句分开,因此如果(当)它崩溃时,它已经保存了:

ThisWorkbook.Save
ThisWorkbook.Close

Can anyone shed some lights?任何人都可以点亮一些灯吗? I'm really lost.我真的很失落。 I tried all the alternatives I could think off (activeworkbook...)我尝试了所有我能想到的替代方案(activeworkbook ...)

Tl;dr: "ThisWorkbook.Close" Causes excel to crash Tl; dr: “ThisWorkbook.Close”导致excel崩溃

This is a standard bug in Microsoft Excel.这是 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:为了解决这个问题,你可以试试这个:

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让我知道它是否有帮助

This happened to me because I had external links that would not update.这发生在我身上,因为我有无法更新的外部链接。 To fix this, I went to Data -> Edit Links -> Break Link.为了解决这个问题,我去数据 -> 编辑链接 -> 断开链接。 Once I broke all of those links, ActiveWorkbook.Close savechanges:=True worked properly.一旦我破坏了所有这些链接,ActiveWorkbook.Close savechanges:=True 就可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由 ThisWorkbook.Close 调用时,BeforeClose 脚本中的 Excel 取消保护工作表不起作用 - Excel unprotect sheet in a BeforeClose script not working when called by ThisWorkbook.Close 使用Excel VBA,如何在第二个工作簿中的“ thisworkbook.close”事件之后使我的原始代码继续执行? - Using Excel VBA, how do I keep my original code executing after a 'thisworkbook.close' event in a 2nd workbook? Excel VBA ThisWorkbook关闭停止工作 - Excel VBA ThisWorkbook Close Stopped Working Excel.ThisWorkbook和ThisWorkbook之间的区别? - Difference between Excel.ThisWorkbook and just ThisWorkbook? Excel VBA-如果activeworkbook是thisworkbook - Excel VBA - if activeworkbook is thisworkbook 在Excel中解析数​​据会导致崩溃 - Parsing Data in Excel Causes Crash Windows(ThisWorkbook.Name).Visible = True 导致 Excel 的自动恢复文件出错 - Windows(ThisWorkbook.Name).Visible = True causes error on Excel's auto-recovered files Excel VBA:尽管有此工作簿,但ActiveX调整大小后,关闭时会提示保存。 - Excel VBA: On Close Save Prompt after ActiveX Resize Despite Thisworkbook.Saved=True 此工作簿在 Excel 2018 中不起作用? - ThisWorkbook Not Working in Excel 2018? Excel应用程序在ThisWorkbook.Save上崩溃-ThisWorkbook是一个加载项 - Excel application crashing on ThisWorkbook.Save - where ThisWorkbook is an add-in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM