vba 不保存宏

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

Don't Save macro

excelvbaexcel-vba

提问by Trying_hard

I need to open and close a file using a macro, but I don't want to save it. I can get to wear excel prompts you to Save or Don't save, what is the VBA command for dont save. This is what I am using I just need it to not save and close excel all the way.

我需要使用宏打开和关闭文件,但我不想保存它。我可以穿excel提示你保存或不保存,不保存的VBA命令是什么。这就是我正在使用的我只需要它不要一直保存和关闭excel。

Sheets("Sheet1").Select
Range("A1").Select

Sheets("Sheet6").Select
Range("A1").Select

Workbooks.Open Filename:= _
    "X:\File.xlsx"
Workbooks.Close

回答by Scott Holtzman

Place Falsein first argument after Close method to tell VBA to not save the Workbook changes. So:

放置False在后关闭方法的第一个参数告诉VBA不保存工作簿的变化。所以:

Workbooks.Close False

or

或者

Workbooks.Close SaveChanges:=False

回答by JMax

If I understand well, try to use Application.DisplayAlerts:

如果我理解得很好,请尝试使用Application.DisplayAlerts

Application.DisplayAlerts=False
Workbooks.Close
Application.DisplayAlerts=True

回答by barrowc

You can use the Savedproperty of the Workbookobject for this. Setting this property to Truewill stop the prompt from appearing (but won't actually save the workbook):

您可以为此使用对象的Saved属性Workbook。将此属性设置为True将停止出现提示(但实际上不会保存工作簿):

Dim wb as workbook

Set wb = Workbooks.Open("X:\File.xlsx")

' do stuff here

wb.Saved = True
wb.Close

See http://msdn.microsoft.com/en-us/library/ff196613.aspxfor reference

请参阅http://msdn.microsoft.com/en-us/library/ff196613.aspx以供参考