VBA & Macro Problems

How to Correctly Close a Word Document from Access VBA

Emma BrownEmma Brown Oct 14, 2026 873 views

Question details

The user needs to properly close a Word document and quit the Word application via Access VBA to prevent hidden instances of Word from staying open.

How to Correctly Close a Word Document from Access VBA
Product
Microsoft Word / Microsoft Access
Device & OS
not provided
Scenario
Automating Word document processing from an Access database using VBA scripts.
Observed behavior
The WINWORD.EXE process remains running in the background because the VBA routine opens a Word document without explicitly closing it and quitting the application, an issue often caused by using generic references like ActiveDocument.
Before you start

Ensure you have saved any critical data in your Access database and review your current VBA code to locate where the Word application object is instantiated.

Solution 1Recommended

Explicitly declare, close, and release Word objects in VBA

Using specific variables for the Word application and document ensures you have complete control over safely closing files and terminating the background process.

Relying on ActiveDocument in Access VBA can inadvertently reference the wrong instance of Word if a user opens another file simultaneously. Explicitly tracking the application and document objects allows you to safely shut them down.

1
Declare specific object variables

In your VBA editor, declare your variables clearly. If using early binding, use 'Dim oApp As Word.Application' and 'Dim oDoc As Word.Document'.

2
Assign the document to a variable upon opening

Instead of relying on ActiveDocument, assign the document directly to your variable when opening it, such as: 'Set oDoc = oApp.Documents.Open(FileName:=LWordDoc)'.

3
Close the document explicitly

After your macro finishes processing the data, close the document using 'oDoc.Close SaveChanges:=False'. Change False to True if your macro needs to save the edits.

4
Release the document object

Free up system memory by setting the document object to nothing using the command 'Set oDoc = Nothing'.

5
Quit Word and release the application object

Terminate the Word process completely by executing 'oApp.Quit', and finally, release the application variable with 'Set oApp = Nothing'.

Explicitly declare, close, and release Word objects in VBA
Recommendation: Using early binding (enabling the Microsoft Word Object Library reference in Access) is highly recommended as it provides code auto-completion and helps prevent syntax errors during development.
Free Microsoft Office alternative

Discover WPS Office for Seamless Document Management

While complex Access VBA integrations rely heavily on the Microsoft Office ecosystem, WPS Office provides a lightweight, highly compatible, and free alternative for your standard Word, Excel, and PowerPoint tasks, complete with macro support in premium versions.

  1. 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
  2. 2. Install the application: Run the downloaded installer and follow the quick on-screen prompts to set up WPS Office.
  3. 3. Open files seamlessly: Double-click your existing .docx or .xlsx files to open them natively in WPS Office with formatting fully preserved.
Fully compatible with Microsoft Word (.docx), Excel (.xlsx), and PowerPoint formats.Lightweight installation that runs smoothly on Windows, Mac, Linux, and mobile devices.Familiar user interface ensuring zero learning curve for switching Office users.Advanced VBA and macro support available to automate your document workflows.
microsoft office alternative - wps office

Frequently Asked Questions

Why does WINWORD.EXE stay open in Task Manager after my macro finishes?

This happens when the VBA code creates a Word Application object but fails to explicitly call the .Quit method or release the object variable (Set oApp = Nothing) before the macro script ends.

What is the difference between early binding and late binding in Access VBA?

Early binding requires setting a reference to the Microsoft Word Object Library in Access, allowing you to declare specific types like Word.Application and utilize IntelliSense. Late binding uses generic Object types, which doesn't require library references but lacks auto-complete features.

Can I use ActiveDocument instead of specific variables in Access VBA?

It is highly discouraged. Using ActiveDocument from an external application like Access can reference the wrong Word instance if the user opens another document simultaneously, leading to unexpected errors or orphaned processes.

How do I save changes before closing the Word document via VBA?

Change the parameter in your close method to SaveChanges:=True (e.g., oDoc.Close SaveChanges:=True). This ensures all modifications made by your script are saved before the document is closed.