vba 关闭所有打开的工作簿而不保存,然后打开另一个工作簿
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28761888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
closing all open workbooks without saving and then open an another workbook
提问by Freek v. wely
I'am looking for the VBA-code for closing all open workbooks without saving and then open an another workbook.
我正在寻找用于关闭所有打开的工作簿而不保存然后打开另一个工作簿的 VBA 代码。
Nows anybody the correct VBA-code?
现在有人知道正确的 VBA 代码吗?
I have now the follow code:
我现在有以下代码:
Private Sub Workbook_Open()
Dim WB As Workbook
For Each WB In Workbooks
If Not (WB Is ActiveWorkbook) Then WB.Close
Next
End Sub
This one i haven't tried jet. I try to make a macro dat starts every day one the same time and closed all workbooks. Then opens workbooks and update the data.
这个我没试过jet。我尝试让宏数据每天在同一时间开始并关闭所有工作簿。然后打开工作簿并更新数据。
回答by Freek v. wely
I have adjust WB.Close savechanges:=False to the VBA-code and its works perfect.
我已经将 WB.Close savechanges:=False 调整为 VBA 代码,它的工作原理很完美。
Thanks
谢谢
回答by Ch.Idea
In my opinion, using macro is not a good way to do this. Check this out. http://blog.contextures.com/archives/2013/04/25/close-all-files-in-excel-2013/
在我看来,使用宏不是做到这一点的好方法。看一下这个。 http://blog.contextures.com/archives/2013/04/25/close-all-files-in-excel-2013/
Or you could do this using cmd command like
或者你可以使用像这样的 cmd 命令来做到这一点
taskkill /IM excel.exe /F
start excel.exe
or making a batch file or a vbscript doing the same.
或者制作一个批处理文件或一个 vbscript 做同样的事情。