ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing files without save (https://www.excelbanter.com/excel-programming/290331-closing-files-without-save.html)

Warren

Closing files without save
 
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



Phil

Closing files without save
 
Not sure about the clipboard thing but the save code is
here

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

JE McGimpsey

Closing files without save
 
Wrap you close code in

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


In article <H3nUb.226302$xy6.1158245@attbi_s02,
"Warren" wrote:

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?


Pete McCosh[_5_]

Closing files without save
 
Application.cutcopymode=false
Activeworkbook.close savechanges:=false


-----Original Message-----
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


JE McGimpsey

Closing files without save
 
Answered only the last part. For the first part, use the SaveChanges
argument:

Workbooks(1).Close SaveChanges:=False

In article ,
JE McGimpsey wrote:

Wrap you close code in

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


In article <H3nUb.226302$xy6.1158245@attbi_s02,
"Warren" wrote:

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?


Jim Feaver

Closing files without save
 
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


"Pete McCosh" wrote in message
...
Application.cutcopymode=false
Activeworkbook.close savechanges:=false


-----Original Message-----
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





All times are GMT +1. The time now is 08:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com