View Full Version : Close messages

06-08-2012, 01:32 PM
I close a worbook with this code:

Sub CloseSheet()

Windows("Avalon Balanced Accounts.xls").Activate
End Sub

After copying data on a workbook and pasting it into a new sheet, I want to close the original worbook in which i copied data from.
After I run this code to close the original workbook, I get two messages about closing the book. The first one asks if i want to save changes, and I want to say "No.". The second message pops up after that and says there is a large amount of information copied, and do I want to save it to the clipboard. I also want to say "No" here. How do I incorporate that into my code to say no to both messages?

06-08-2012, 02:04 PM
Try this:

Sub CloseWorkbook()
ThisWorkbook.Saved = True
Application.CutCopyMode = False
End Sub

Of course you could change ThisWorkbook with ActiveWorkbook or set a variable as a workbook and close that instead...

06-08-2012, 03:52 PM

This should do it. Change "Your Workbook Name" to match your own workbook.

Application.DisplayAlerts = False

Windows("Your Workbook Name.xls").Close

Application.DisplayAlerts = True