Closing files without save

W

Warren

I am writing a macro which opens and closes a series of other workbooks.
When I close a workbook, Excel prompts me if I want to save the file and if
I want to delete whatever is left on the clipboard.

How can I, in VBA, close a workbook without saving it and not have Excel
displaying a dialog box asking if I want to save?
Also, how can I surpress the question about the clipboard, and automatically
have Excel to discard those items left on the clipboard?

Thanks in advance,
Warren
 
P

Phil

Not sure about the clipboard thing but the save code is
here

Workbooks("yourfilename.xls").Close savechanges:=False
 
J

JE McGimpsey

Wrap you close code in

Application.DisplayAlerts = False
Workbooks(1).Close
Application.DisplayAlerts = True
 
J

JE McGimpsey

Answered only the last part. For the first part, use the SaveChanges
argument:

Workbooks(1).Close SaveChanges:=False
 
J

Jim Feaver

A couple other things.

If wb.Saved = false then wb.Save



i = 0

For Each wb In Workbooks

If Not (wb.Name = "Personal.xls") Then

i = i + 1

End If

Next wb



Application.EnableEvents = False

Application.DisplayAlerts = False



If i = 1 Then

Application.Quit

Else

ThisWorkbook.Close (False)

End if

Application.EnableEvents = True

Application.DisplayAlerts = True

Set wb = Nothing

Set ws = Nothing



hth,

Jim Feaver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top