Excel VBA 代码另存为特定文件名并关闭活动工作簿

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1831270/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:10:04  来源:igfitidea点击:

Excel VBA code to SaveAs a specific filename and close the active workbook

excelvba

提问by robinJ

What VBA code do I need to add to the end of an existing sub to save the active workbook as "finaloutput.xls" and then automatically close the workbook without saving changes?

我需要在现有子文件的末尾添加什么 VBA 代码才能将活动工作簿保存为“finaloutput.xls”,然后自动关闭工作簿而不保存更改?

回答by Mike Woodhouse

You could use something as simple as this, which I put in another workbook and executed from the Tools...Macros menu (Alt+F8) after activating the workbook to be saved.

你可以使用像这样简单的东西,我把它放在另一个工作簿中,并在激活要保存的工作簿后从工具...宏菜单 (Alt+F8) 执行。

Public Sub SaveAsAndClose()

    ActiveWorkbook.SaveAs "finaloutput.xls"
    ActiveWorkbook.Close

End Sub