PDA

View Full Version : Close messages



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

Sub CloseSheet()

Windows("Avalon Balanced Accounts.xls").Activate
ActiveWindow.Close
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?

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

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

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

fredlo2010
06-08-2012, 03:52 PM
Hi,

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