5 Smart Ways to Close Multiple Open Documents except the Current One in Your Word

In this post, we will offer you 5 smart ways to close multiple documents except the current one in Word.

Many people prefer to have multiple documents open as a way to improve efficiency. For example, you are writing a chapter of a book, and chances are that you will have to open several documents for reference. Once finishing the draft, you shall wonder if there is a way to close a batch of files at one time.Close Multiple Open Documents except the Current One

Here are 5 different scenarios, and we will provide you 5 macros to accomplish each task quickly.

Method 1: Close All Open Documents except the Current One

Word has a built-in command for you to close all open documents in one click. But it goes nowhere further. Thus, we want you to be able to close all documents but leave the current one open.

  1. First of all, press “Alt+ F11” to trigger VBA editor.
  2. Next create a new module by clicking “Normal” first.
  3. Then click “Insert” tab and choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  4. Double click on new module to open it.
  5. Now paste the following codes:
Sub CloseAllDocsExceptCurrentOne()
  Dim objDoc As Document
  Dim objDocumentsToBeClosed As New Collection
  Dim nCount As Integer
 
  nCount = Application.Documents.Count
  For nIndex = 1 To nCount
    Set objDoc = Application.Documents.Item(nIndex)
    If objDoc.FullName <> ActiveDocument.FullName Then
      objDocumentsToBeClosed.Add objDoc
    Else
      Exit For
    End If
  Next nIndex
  For Each objDoc In objDocumentsToBeClosed
    objDoc.Close SaveChanges:=wdSaveChanges
  Next objDoc
End Sub
  1. Last but not the least, click “Run” to get the codes executed.Paste Codes->Click "Run"

Then your current document remains open, the one and only.

Method 2: Close All Documents Opened after the Current One

You may have a lot documents open, and surely there is a time difference between the open of each individual one. The following macro closes all documents opened after the current one in time order.

  1. Firstly, repeat steps in method 1 to install and run a macro.
  2. Secondly, replace that macro with this one:
Sub CloseAllDocsOpenedAfterCurrentOne()
  Dim objDoc As Document
  Dim objDocumentsToBeClosed As New Collection
  Dim nCount As Integer
 
  nCount = Application.Documents.Count
  For nIndex = 1 To nCount
    Set objDoc = Application.Documents.Item(nIndex)
    If objDoc.FullName = ActiveDocument.FullName Then
      Exit For
    Else
      objDocumentsToBeClosed.Add objDoc
    End If
  Next nIndex
 
  For Each objDoc In objDocumentsToBeClosed
    objDoc.Close SaveChanges:=wdSaveChanges
  Next objDoc
 
  Set objDocumentsToBeClosed = Nothing
End Sub

Method 3: Close All Documents Opened before the Current One

Since we can close all documents opened after the current one with method 2, we can close all documents opened before with this macro.

  1. To start with, install and run a macro with exact the same steps in method 1.
  2. Next use these codes:
Sub CloseAllDocsOpenedBeforeCurrentOne()
  Dim objDoc As Document
  Dim objDocumentsToBeClosed As New Collection
  Dim nCount As Integer
 
  nCount = Application.Documents.Count
  For nIndex = nCount To 1 Step -1
    Set objDoc = Application.Documents.Item(nIndex)
    If objDoc.FullName = ActiveDocument.FullName Then
      Exit For
    Else
      objDocumentsToBeClosed.Add objDoc
    End If
  Next nIndex
 
  For Each objDoc In objDocumentsToBeClosed
    objDoc.Close SaveChanges:=wdSaveChanges
  Next objDoc
 
  Set objDocumentsToBeClosed = Nothing
End Sub

Method 4: Close the Current Document together with All Documents Opened after It

Similarly, install and run the following codes as described in method 1:

Sub CloseCurrentOneWithAllOpenedAfterIt()
  Dim objDoc As Document
  Dim objDocumentsToBeClosed As New Collection
  Dim nCount As Integer
 
  nCount = Application.Documents.Count
  For nIndex = 1 To nCount
    Set objDoc = Application.Documents.Item(nIndex)
    If objDoc.FullName = ActiveDocument.FullName Then
      objDocumentsToBeClosed.Add objDoc
      Exit For
    Else
      objDocumentsToBeClosed.Add objDoc
    End If
  Next nIndex
 
  For Each objDoc In objDocumentsToBeClosed
    objDoc.Close SaveChanges:=wdSaveChanges
  Next objDoc
 
  Set objDocumentsToBeClosed = Nothing
End Sub

Method 5: Close the Current Document together with All Documents Opened before It

Follow all required steps to install and run this macro:

Sub CloseCurrentDocWithAllOpenedBeforeIt()
  Dim objDoc As Document
  Dim objDocumentsToBeClosed As New Collection
  Dim nCount As Integer
 
  nCount = Application.Documents.Count
  For nIndex = nCount To 1 Step -1
    Set objDoc = Application.Documents.Item(nIndex)
    If objDoc.FullName = ActiveDocument.FullName Then
      objDocumentsToBeClosed.Add objDoc
      Exit For
    Else
      objDocumentsToBeClosed.Add objDoc
    End If
  Next nIndex
 
  For Each objDoc In objDocumentsToBeClosed
    objDoc.Close SaveChanges:=wdSaveChanges
  Next objDoc
 
  Set objDocumentsToBeClosed = Nothing
End Sub

Fix Document Corruption Correctly

An errant operation in Word can cause one or more documents to be broken. The point is that you must know the right way to hand such a crisis. And in this case, your best chance to retrieve data is to utilize a Word repair tool.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover xls and pdf repair software products. For more information visit www.datanumen.com

Comments are closed.