709-218-7927

The Landfall Garden House

60 Canon Bayley Road

CANADA A0C 1B0

CPRGreaves@gmail.com

Home

Christopher Greaves

Close All But Active

Saturday, June 25, 2011

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

7092187927 CPRGreaves@gmail.com

Bonavista, Friday, December 04, 2020 5:55 PM

Copyright © 1996-2020 Chris Greaves. All Rights Reserved.