Free Microsoft Excel 2013 Quick Reference

VBA - Close without saving changes

The system runs several reports each night, and I have a macro that opens the
report it needs automatically, uses the data, then closes the report.
Even in cases where all i've done is copy data from this report it asks me
occasionally if I want to save changes. Sometimes I do make changes.

Is there a way in a macro that I can set it to automatically close a file
without either saving it, or prompting me?
Any changes to these reports doesn't want to be saved so they can be used by
other people, and I generally like the prompt on a usual basis, but its one I
would rather be without while a macro is running.

Anything I can put before
Or in it, or something like that?

Post your answer or comment

comments powered by Disqus
When I run the following VBScript it prompts whether to save changes or not before closing the file. I want to automate the script without saving the changes. What is the solution that it does not prompt and close without saving

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:test.xls",,true)

objExcel.Run "ReformatR"

For Each pc In objWorkbook.Charts
   pc.Export "C:"+pc.Name+".png", "png"


Hi Folks
I've currently got a macro which is working as expected.

What I would like to add is a Message Box that tells the user that the Macro has run and to click 'ok' to close the file WITHOUT saving changes. No other options should be available.

Also, I presume that the Message Box code should be written after 'Loop Until'??

 Sub Transfer_Revenue()



Loop Until IsEmpty(ActiveCell.Offset(1, 0))
End Sub
Great forum, thanks for any help folks.

In Excel 2003, I would like the save menu to pop up "do you want to save
changes that you made to 'Filename.xls'?" when I click on File, then Close.

Sometimes I am doing a calc in the file itself, which is not meant to be
saved. In prior versions of Excel, using File->Close does not automatically
save changes. Does anyone know how to make the menu pop up, or turn off the
autosave function?


In Excel 2003, I would like the save menu to pop up "do you want to save
changes that you made to 'Filename.xls'?" when I click on File, then Close.

Sometimes I am doing a calc in the file itself, which is not meant to be
saved. In prior versions of Excel, using File->Close does not automatically
save changes. Does anyone know how to make the menu pop up, or turn off the
autosave function?


Hi everybody,

I have the following code for closing the current workbook without saving changes >>

I want it to be developed to close all active workbooks

Private Sub Workbook_BeforeClose(Cancel As
ActiveWorkbook.Saved = True
End Sub
Thank you,

I was working in excel and wrongly I closed the excel file without saving the

I wish to recover my workdone in excel workbook that was closed without

Please let me know the steps I need to follow for retrieving my data.


closing excel workbook no save without save messagebox

close without save....

*** Sent via Developersdex ***

Hi friends,

I want to close a tab delimited Txt file that is open in Excel, thru' a macro, without the save changes dialog box appearing.

is this possible ?


Hi All,

First apologies for asking word related question in excel forum.

My Requirement is to Close the word document by saving the changes without throwing the prompt.

I have tried quit and close with save changes but was not working, then i made displayalerts false, but still prompt is being thrown.

Am I missing something, is there some codes to be coded before closing and saving using VBA.

And most importantly, i can't use application , as it will close all the word document. I want to close only that document for which macro has been written, secondly, the word doc is supposed to used as a template so the name can change, so i can use ThisDocument("Name.doc").



I want to add a statement to my existing vba code to close a file without saving changes.

I have ActiveWindow.Close but this doesn't seem to work, when stepping into the code I will still get the 'Do you want to save changes?' message box.

Any ideas for the correct code? The file name will be different each time the macro is run.

I'd also like the alternative whereby I do save changes if poss (for another macro)

Hello all,

Anyone know the VBA code to close a workbook, and not save it? I need it to open a workbook, run a macro, and close without saving. The code I have thus far is:

Application.Workbooks.Open ("serverfile1file2aaa.xls")
    Sheets("Call Report").Select
    Application.Run ("aaa.xls!macro")
but this brings up the 'do you want to save changes' pop-up.

Cheers guys.


I'm using the line

Activeworkbook.close , False

in my code to close multiple workbooks without saving. It works fine on most books but some users have Office XP and some have Office 2003, as is on my machine.

If a sheet has been last saved on office xp I get a box asking if I want to save changes and "Microsoft Office Excel recalculates formaulas when opening files savedby an earlier version of excel"

How can I stop this displaying?

Dear all, I recorded a macro which opens a sheet and takes the data I need and then closes the sheet but hangs on "do you want to save any changes dialogue box"

I click no and then it completes the close down.

Is there anything I can add to the code to avoid clicking "no"

Thanks in advance

I run a macro that opens onther workbbok and prints some sheets.
The workbook that i open also contains a macro that runs when opened. When the macro from the first workbook closes this it brings up a message box asking to save changes which i have to manually click.

I need a bit of code to not save the changes to the workbook or not to be asked.

Also should the code go in the first workbook (where the code is run from) or from the workbook that is being closed

Note that I am opening and closing muiltiple workbooks which i would like this to apply to


I recorded a simple macro that opens various files, manipulates them, and
then builds a report. After doing some manipulation of 3 files, I want the
macro to close them without saving automatically. When I recorded the macro,
it brought up the dialog box "Do you want to save?" when I attempted to close
each file. Now when I run the macro, the same dialog boxes come up, which
requires my intervention. Is there a simple fix to disable this prompt from
coming up and automatically close the files without saving? Below is an
example of the recorded VBA.

Windows("Modular Sales by Item Pivot.xls").Activate
Application.CutCopyMode = False




i'm using a VBA code to close a workbook when a user clicks on a certain button

HTML Code: 
However an automated msg appears, asking the user if they wish to save before closing. Is there a way to avoid this msg
appearing or to automate a no answer to the question.

thanks in advance

I entered tons of data, was trying to paste a section into an e mail, somehow
managed to close it all without saving changes. The original file is
available minus the changes. Is there any way to restore it to like 5 minutes
before closing. This would be huge.
Sorry novice needing help

Hi guys,
I have 2 problems actually.

I need the code for closing a workbook without saving.


help with the following code cuz its not working. It uses date from a global string and puts it in a file name.

ActiveWorkbook.SaveAs Filename:="C:Documents and SettingsqalbashDesktopCurrent ProjectsYTD Gross and Net Automated
Report" & "GNS Industry Comparative Reports" & strDate 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
Thanks ahead of time.

Hi, I set up a code to first print a template and then close it without saving. But sometimes the template still asks if you wish to save after printing? Any help greatly appreciated. Here is the code:

Sub Print_Seq()
' Print_Seq Macro
' Macro recorded 1/18/2008 by Lourie  Repp
' Keyboard Shortcut: Ctrl+p
    ActiveWorkbook.PrintOut From:=1, To:=2, Copies:=1
    objExcel.DisplayAlerts = False
End Sub

I am trying to close a file within a macro having copied data from that into a target workbook.

Am using .. ActiveWorkbook.Close .. to do this. But want to close without saving and without seeing the "do you want to save" dialogue box. Cannot find how to do this.

Any ideas ? Thanks.

Morning All

Hope you enjoying you day / night (if your on the otherside of the globe).

I've got the following code to save some open text files and need some help saving the files as .xls without renaming worksheets (or losing any multiple sheets)

I wish to prompt the users to save the file to the location that they select (which is working ok) with a generic name followed by date.

I want to save the files as excel which isn't quite working as when you exit the file it will still prompt if you want to save changes - and if you click yes it will tell you that there are features which are not supported by txt files. Also one workbook has mutliple sheets that I need to keep.

Also I can't get it to save the files without renaming the first worksheet in it.
The first worksheet in both files need to remain with the name Master - currently its renaming the sheet the same as the filename.
(Next month the op file will become last months file and the macro will be looking for a worksheet named Master)

If anybody has any suggestions how I can do this it would be greatly appreciated.

P.S. I'm using excel 2002.

Sub CloseAndSave()

    Dim strFilePrefix1 As String
    Dim strFilePrefix2 As String
    Dim strFilePrefix3 As String


'op File - text file which needs to be saved
    strFilePrefix1 = ActiveCell.Value
'Mgmt File - text file which needs to be saved
    strFilePrefix2 = ActiveCell.Value
'Last month - excel workbook which is closed without saving changes
    strFilePrefix3 = ActiveCell.Value
Workbooks([strFilePrefix3]).Close savechanges:=False


Dim SaveMgmt As String

SaveMgmt = Application.GetSaveAsFilename("SAF Mgmt File" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 2) & ".xls", , ,
"Save the Mgmt File...")
ActiveWorkbook.SaveAs SaveMgmt


Dim SaveOp As String

SaveOp = Application.GetSaveAsFilename("SAF Op File" & Left(Date, 2) & Mid(Date, 4, 2) & Right(Date, 2) & ".xls", , , "Save
the Operations File...")
ActiveWorkbook.SaveAs SaveOp

End Sub


i have a number of macro's that open and close different wokbooks to analyse
data. at the moment they run fine but i have to manualy click 'no' on saving
changes and to indicate that the large amount of information on the clipboard
is no longer required. can someone please tell me the code to enter to do

many thanks

I just closed a file (by accident) that I have been working on all day. In my rush to get out I closed all without saving. Then noticed that the file in question was last modified yesterday, meaning I did not do a save all day.

Is there a way to recover this?

I have worksheets email to me. I want to have a simple macro to close them
without saving them, to keep the integrity of what was emailed to me. Is
there a way of doing this ??

thanks ... Roger

No luck finding an answer? You could always try Google.