PDA

View Full Version : Solved: Close all but Activesheet



kisinana
07-26-2008, 06:41 AM
Still searching for a way to close second date that macro seems to got to and read this

Option Explicit
Sub CloseAllExceptActive_NoSave()
With Application
.ScreenUpdating = False
'Loop Through open documents
Do Until .Documents.Count = 1
'Close no save
.Documents(1).Close SaveChanges:=wdDoNotSaveChanges
Loop
.ScreenUpdating = True
End With
End Sub

The question it came from was about word. Can I just change "Documents" to "Workbooks" to make it work in excel ? Or do I need to alter it at all?

Bob Phillips
07-26-2008, 06:48 AM
Sub CloseAllExceptActive_NoSave()
Dim wb As Workbook

With Application

.ScreenUpdating = False
For Each wb In .Workbooks

If wb.Name <> ActiveWorkbook.Name Then

wb.Close savechanges:=False
End If
Next wb

.ScreenUpdating = True
End With
End Sub

kisinana
07-26-2008, 06:57 AM
Thank you
One other question I now want the active workbook to save its changes
so after this sub has run I can put in the code
Activeworkbook.save

mdmackillop
07-26-2008, 07:14 AM
You can run that at any time, before or after closing the other workbooks