Fix Word VBA Error 5941 When Activating a Document from Access
Question details
Fix an Access VBA routine that opens Word documents but fails when activating a document window.

- Product
- Microsoft Access and Microsoft Word VBA
- Device & OS
- not provided
- Scenario
- An Access macro opens Word documents, copies their contents, and pastes them into a destination document.
- Observed behavior
- Documents open successfully, but activating a window by its full path and Compatibility Mode caption causes Runtime Error 5941 on some computers.
Open the Access VBA editor and locate the code that opens and activates the Word document. Identify the Word Application object, source file path, and destination document used by the routine.
Store Word document references instead of matching window captions
Use this approach to avoid caption differences and work directly with the documents opened by Access.
Word window captions can vary by version and may or may not include Compatibility Mode. A saved Document object avoids depending on that caption or on whichever document is currently active.
In the Access VBA editor, add `Dim sourceDoc As Object` and `Dim destDoc As Object` to the routine. This example uses late-bound object variables.
Before opening a source file, save the intended destination document in `destDoc`. For example, if it is currently active in the existing Word Application object `wordApp`, use `Set destDoc = wordApp.ActiveDocument`.
Replace the open-and-activate sequence with `Set sourceDoc = wordApp.Documents.Open(filePath)`, using the routine's existing Word Application object and source file path.
Use `sourceDoc.Content.Copy` to copy the source, then use `destDoc.Range(destDoc.Content.End - 1, destDoc.Content.End - 1).Paste` to paste at the end of the destination. Repeat with a new `sourceDoc` reference for each file.
Remove the window-caption activation call. If a later operation requires the source document to be active, use `sourceDoc.Activate` instead.

Use the document name when looking up an open Word document
Use this option if the routine must retrieve an already-open document and cannot retain its object reference.
Work with Word documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Office files. It can help you move everyday document work to WPS, but it does not fix Microsoft Access-to-Word VBA activation errors.

Frequently Asked Questions
Why does the activation code work on one computer but not another?
Word versions can display different window captions, including whether they append Compatibility Mode. Replace the exact caption lookup with the Document object returned by `Documents.Open`.
Does opening a Word document automatically make it active?
The most recently opened document is normally active, so a separate activation may not be necessary. Store the result of `wordApp.Documents.Open(filePath)` and use that reference for subsequent operations.
Is Error 5941 necessarily caused by permissions?
No. In this scenario, a missing or mismatched document or window reference is a more likely cause. Check the reference and caption used by the activation call before assuming it is a permissions issue.
How can I return to the destination document without relying on ActiveDocument?
Save the destination as a Document object before opening the source. Then use that reference, such as `destDoc.Range(...).Paste`, or call `destDoc.Activate` if activation is required.




