Saturday, June 25, 2011

Close All But Active

From time to time I find that I have opened a slew of documents, just to help me understand the one document I'm working on.
In this case I want to violate my Golden Rule of "Never Close, never Minimize", and close all open documents EXCEPT THE ACTIVE DOCUMENT without saving a single one; discard all recent changes.
This little macro does the trick.
Public Sub CloseAllButActive()
''' Close all open documents EXCEPT THE ACTIVE DOCUMENT without saving a single one; discard all recent changes.
If Documents.Count > 0 Then
Dim docSave As Document
Set docSave = ActiveDocument
Dim doc As Document
For Each doc In Application.Documents
If doc <> docSave Then
doc.Close savechanges:=wdDoNotSaveChanges
Else
End If
Next doc
Else ' nothing to do
End If
End Sub

No comments:

Post a Comment