使用VBA关闭Excel应用程序 [英] Closing Excel Application using VBA
问题描述
我没有成功使用以下。活动工作簿确实关闭,但是excel窗口仍然保持打开状态。
Application.ActiveWindow.Close SaveChanges:= False
ActiveWorkbook.Close SaveChanges:= False
终止应用程序的命令是什么?
编辑
再说一点:在工作簿中打开事件我运行一个宏。我想在该宏完成时终止应用程序。我也尝试过没有成功。
Private Sub Workbook_Open()
Macro_MyJob
Application.Quit
End Sub
我应该把这个Application.Quit命令放在哪里?
我想你的问题是在发送命令退出应用程序之前关闭调用宏的文档。
在这种情况下,您的解决方案是不发送关闭工作簿的命令。相反,您可以将工作簿的已保存状态设置为true,这将绕过关于关闭未保存的书的任何消息。注意:这不保存工作簿;它只是让它看起来像保存。
ThisWorkbook.Saved = True
/ pre>
然后,紧接着
应用程序。退出
I have used the following without success. The active workbook closes, indeed, but the excel window remains open.
Application.ActiveWindow.Close SaveChanges:=False ActiveWorkbook.Close SaveChanges:=False
Which is the command that terminates the application?
EDIT
To say a little more: In the workbook Open event I run a macro. I want to terminate the application when that macro finishes. I also tried this without success.
Private Sub Workbook_Open() Macro_MyJob Application.Quit End Sub
Where should I put this Application.Quit command?
解决方案I think your problem is that it's closing the document that calls the macro before sending the command to quit the application.
Your solution in that case is to not send a command to close the workbook. Instead, you could set the "Saved" state of the workbook to true, which would circumvent any messages about closing an unsaved book. Note: this does not save the workbook; it just makes it look like it's saved.
ThisWorkbook.Saved = True
and then, right after
Application.Quit
这篇关于使用VBA关闭Excel应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!