709-218-7927

The Landfall Garden House

60 Canon Bayley Road

Bonavista, Newfoundland

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

709-218-7927 CPRGreaves@gmail.com

Bonavista, Sunday, December 08, 2024 9:33 AM

Copyright © 1990-2024 Chris Greaves. All Rights Reserved.