简体   繁体   English

Excel VBA ThisWorkbook关闭停止工作

[英]Excel VBA ThisWorkbook Close Stopped Working

I am curious as to the possible reasons why ThisWorkbook.Close has stopped working when a button on a userform is clicked. 我对单击用户窗体上的按钮时ThisWorkbook.Close停止工作的可能原因感到好奇。 Now I receive a 1004 error 现在我收到一个1004错误

Method Close or object Workbook failed 方法关闭或对象工作簿失败

Previous backups of the workbook are fine and close down without error. 该工作簿的先前备份很好,并且可以正常关闭。 Events have not been disabled. 活动尚未禁用。 ThisWorkbook.Save or Application.Quit work ok. ThisWorkbook.Save或Application.Quit工作正常。

Could getting trapped and have to resort to using Ctrl-Alt-Del to kill Excel to close the workbook do anything? 可能会陷入困境,不得不诉诸使用Ctrl-Alt-Del来杀死Excel来关闭工作簿的功能吗?

Any ideas? 有任何想法吗?

Private Sub cmbClose_Click()

On Error GoTo errHandler:

'   Close workbook
ThisWorkbook.Close

'   Error handler
On Error GoTo 0
Exit Sub

errHandler::
    MsgBox "An Error has Occured " & vbCrLf & "The error number is : " _
    & Err.Number & vbCrLf & Err.Description & vbCrLf & vbCrLf & _
    "Please take a screenshot of this message and contact the developer "

End Sub

Just my guesses, but did you save your workbook before closing? 只是我的猜测,但是您在关闭之前是否保存了工作簿? I changed 我变了

ThisWorkbook.Close

to

ThisWorkbook.Close False

and it works perfectly as a sub. 它可以完美地作为潜水艇。 ( The "False" there is for property "SaveChanges", so I'm forcing it to close without prompting for saving coz I was testing this on a newly created workbook ) (属性“ SaveChanges”具有“ False”,因此我在不提示保存的情况下强制关闭它,因为我正在新创建的工作簿上对此进行测试)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM