VBA Close workbook without saving message box

Diogenes

New Member
Joined
Apr 2, 2014
Messages
34
Hi all,
I am trying to close a workbook that I have just copied data from and I don’t want to receive the “do I want to close without saving” message.
The section of code in question currently looks like this:
Code:
    ' Close customer workbook
    customerWorkbook.Activate
    Application.CutCopyMode = False
    customerWorkbook.Close , SaveChanges = False
       
    targetSheet.Activate
I still get the message every time any idea why?
I am using excel 2007.
Many thanks,
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi there,

I've not tested this but used something similar on other workbooks.

Code:
   ' Close customer workbook
    customerWorkbook.Activate
    Application.CutCopyMode = False
    
    Application.DisplayAlerts = False
    
    customerWorkbook.Close , SaveChanges = False
    
    Application.DisplayAlerts = True
       
    targetSheet.Activate
 
Upvote 0
Try

Rich (BB code):
Application.DisplayAlerts = False
customerWorkbook.Close SaveChanges:=False ' No comma, := not =
Application.DisplayAlerts = True
 
Upvote 0
Thanks for the quick replies guys.
My code now looks like this:
Code:
    ' Close customer workbook
    customerWorkbook.Activate
    Application.CutCopyMode = False
    Application.DisplayAlerts = False
    customerWorkbook.Close SaveChanges:=False
    Application.DisplayAlerts = True
      
    targetSheet.Activate
I am still getting the same message!
Could it be something in my setup of my version of excel around saving i.e. in the options somewhere?
Thanks again,
 
Upvote 0
Sledgehammer approach

Rich (BB code):
' Close customer workbook
    customerworkbook.Activate
    customerworkbook.Saved = True ' marks as saved but doesn't save
    Application.CutCopyMode = False
    Application.DisplayAlerts = False
    customerworkbook.Close SaveChanges:=False
    Application.DisplayAlerts = True
      
    targetSheet.Activate
 
Upvote 0
This helped me as well - thanks as always VoG for a great answer, and thanks Diogenes for asking the question!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top