Reputation: 9501
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.
Sheets("Sheet1").Select
Range("A1").Select
Sheets("Sheet6").Select
Range("A1").Select
Workbooks.Open Filename:= _
"X:\File.xlsx"
Workbooks.Close
Upvotes: 4
Views: 9579
Reputation: 10679
You can use the Saved
property of the Workbook
object for this. Setting this property to True
will stop the prompt from appearing (but won't actually save the workbook):
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.aspx for reference
Upvotes: 2
Reputation: 27239
Place False
in first argument after Close method to tell VBA to not save the Workbook changes. So:
Workbooks.Close False
or
Workbooks.Close SaveChanges:=False
Upvotes: 11
Reputation: 26591
If I understand well, try to use Application.DisplayAlerts
:
Application.DisplayAlerts=False
Workbooks.Close
Application.DisplayAlerts=True
Upvotes: 3