Word

Close all open Word documents and quit Word

Ease of Use

Easy

Version tested with

2000, 2003 

Submitted by:

MOS MASTER

Description:

Programmatically close all open Word documents and quit Word. 

Discussion:

You want an easy way to close all open documents and want to quit Word at the same time. The sub below provides that. If you need to save every doc then change [b]SaveChanges to wdSaveChanges[/b] Important: this sub has to run global in Normal.dot or an addin to perform correctly and quit Word after execution. 

Code:

instructions for use

			

Sub CloseAll() 'Close all open files and shutdown Word With Application .ScreenUpdating = False 'Loop Through open documents Do Until .Documents.Count = 0 'Close no save .Documents(1).Close SaveChanges:=wdDoNotSaveChanges Loop 'Quit Word no save .Quit SaveChanges:=wdDoNotSaveChanges End With End Sub

How to use:

  1. Open your Word document.
  2. Press Alt + F11 to open VBE.
  3. Press CTRL+R to view Project Explorer
  4. Select Normal Project (Mother of all Word documents)
  5. Choose: Insert-Module. (Insert -> module)
  6. Paste the code there in the window at right. (F7)
  7. Close VBE (Alt + Q or press the X in the top right hand corner).
  8. Save the file.
 

Test the code:

  1. From Word, press Alt + F8 to open the macro dialog box.
  2. Select CloseAll
  3. Click Run.
 

Sample File:

Close all open Word documents and quit Word.zip 5.37KB 

Approved by mdmackillop


This entry has been viewed 137 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express