How to Fix Word VBA Error 5941 When Comparing Windows Side by Side
Question details
The user encounters VBA runtime error 5941 when running a macro to compare windows side by side.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Using a VBA macro to open a new view of the active document and compare both windows side-by-side using the Windows.CompareSideBySideWith method.
- Observed behavior
- The macro throws 'Runtime error 5941: The requested member of the collection does not exist' on the first execution. This happens because creating a new window changes the original document's caption (e.g., from 'sample.docx' to 'sample.docx:1' and 'sample.docx:2'), invalidating the string reference.
Ensure you have saved your current VBA project and active documents before testing macros, as runtime errors can interrupt your workflow and leave Word in a split-screen state.
Use Window Object Variables Instead of Captions
Modify your VBA code to store a direct reference to the Window object rather than relying on its text caption, which changes dynamically.
When you use the NewWindow command, Word automatically appends instance numbers to the document's window captions (e.g., changing 'sample.docx' to 'sample.docx:1').
If your macro captured the caption 'sample.docx' as a string before opening the new window, passing that string to Windows.CompareSideBySideWith will trigger Error 5941 because 'sample.docx' no longer exists in the Windows collection. By using a Window object variable, the macro bypasses this string matching issue entirely.
Press Alt + F11 to open the Microsoft Visual Basic for Applications window, then locate the module containing your side-by-side macro.
Replace the string declaration (Dim s As String) with an object declaration: Dim origWin As Window.
Before the NewWindow command, capture the original window by adding: Set origWin = ActiveWindow.
Run the new window command using ActiveDocument.ActiveWindow.NewWindow, then compare them using the object: Windows.CompareSideBySideWith origWin.
If you want the windows to scroll independently, leave the line Windows.SyncScrollingSideBySide = False at the end of your Sub routine.

Append the Window Number to the String Reference Manually
If you must use string variables, adjust your macro to anticipate the new window caption format by appending the ':1' suffix.
Compare Documents Side by Side Easily in WPS Office
Instead of writing complex VBA macros to handle document views and risking runtime errors, WPS Writer provides a built-in, intuitive tool to view documents side by side natively.
- 1. Open Your Documents: Launch WPS Writer and open the two documents (or multiple views of one document) that you want to compare.
- 2. Navigate to the View Tab: Click on the 'View' tab located on the top ribbon of the application.
- 3. Activate Side-by-Side Mode: Click the 'View Side by Side' button to instantly snap your documents next to each other.
- 4. Toggle Synchronous Scrolling: Click the 'Synchronous Scrolling' button right below it to choose whether scrolling one document scrolls the other automatically.

Frequently Asked Questions
Why does Word rename my document window to filename:1 and filename:2?
Word assigns these numerical suffixes when multiple views or windows of the exact same document are open simultaneously. This helps the system and the user differentiate between the different views of the same file.
What does Runtime Error 5941 mean in Word VBA?
Runtime Error 5941, reading 'The requested member of the collection does not exist', occurs when your VBA code tries to interact with an item (like a Window, Bookmark, or Document) that is missing, closed, or incorrectly named in the specified collection.
How do I disable synchronous scrolling without using VBA?
If you are in Side-by-Side view, go to the 'View' tab on the ribbon and click the 'Synchronous Scrolling' button to toggle it off. This allows you to scroll through each document window independently.




