使用 VBA 关闭 Excel 应用程序 [英] Closing Excel Application using VBA

查看:74
本文介绍了使用 VBA 关闭 Excel 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下方法但没有成功.活动工作簿确实关闭了,但 Excel 窗口仍然打开.

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?

编辑

多说一点:在工作簿打开事件中,我运行了一个宏.我想在该宏完成后终止应用程序.我也试过了,没有成功.

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

我应该把这个 Application.Quit 命令放在哪里?

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.

在这种情况下,您的解决方案是不发送关闭工作簿的命令.相反,您可以将工作簿的已保存"状态设置为 true,这将绕过有关关闭未保存书籍的任何消息.注意:这不会保存工作簿;它只是让它看起来像是被保存了.

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

然后,紧接着

Application.Quit

这篇关于使用 VBA 关闭 Excel 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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