logo
search
Document Editing Problems

How to Fix Word Run-Time Error 5941 When Replacing Long Text

Amos GikundaAmos Gikunda Oct 22, 2026 868 views

Question details

The user needs to resolve a Run-time error 5941 in a Word VBA macro designed to find and replace text strings longer than the standard 255-character limit.

How to Fix Word Run-Time Error 5941 When Replacing Long Text
Product
Microsoft Word
Device & OS
not provided
Scenario
Executing a custom VBA macro to bypass the native 255-character limit in Word's Find and Replace tool.
Observed behavior
The macro halts execution and displays Run-time error 5941 because the document structure or collection member referenced by the code does not match the macro's assumptions.
Before you start

Create a backup copy of your document before running custom VBA macros to ensure you can easily revert changes if the text replacement modifies unintended paragraphs.

Solution 1Recommended

Use a Paragraph-Based Macro Replacement

Bypass the 255-character Find and Replace limit by targeting specific document paragraphs and directly modifying their text ranges.

Standard Word Find/Replace limits strings to 255 characters. When a macro exceeds this limit or encounters unexpected document structures like inline pictures or complex text boxes, Error 5941 occurs.

By iterating through paragraphs and adjusting the text range to exclude the paragraph mark, you can safely swap in your long text blocks without triggering collection errors.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor in Microsoft Word.

2
Insert a New Module

Click 'Insert' in the top menu and select 'Module' to create a blank workspace for your custom macro.

3
Paste and Customize the Code

Paste your paragraph-based VBA script. Ensure you specify the character length limit (e.g., replaceLength = 548) and define your exact replacement string inside the code.

4
Run the Macro

Press F5 or click the green 'Run' button in the toolbar to execute the macro and apply the text replacements across your active document.

Use a Paragraph-Based Macro Replacement
Formatting Tip: Ensure your macro code includes the logic to exclude the paragraph mark (using .End = .End - 1) so the document's original formatting structure is preserved.
Free Microsoft Office alternative

Edit and Manage Complex Documents with WPS Office

Tired of troubleshooting complex VBA macros and cryptic Run-time errors? WPS Office offers a highly compatible, lightweight, and user-friendly alternative to Microsoft Word. Easily manage large documents, perform advanced text editing, and seamlessly open your existing Word files for free.

  1. 1. Download the Software: Download and install WPS Office Free from the official website to your device.
  2. 2. Open Your Document: Launch WPS Writer and open your existing Microsoft Word (.docx) document seamlessly without losing formatting.
  3. 3. Edit Effortlessly: Use the intuitive built-in editing tools to modify your long text blocks and document structures quickly.
Fully compatible with Microsoft Word (.docx) formatsIntuitive interface that eliminates steep learning curvesLightweight application that runs smoothly on all devicesBuilt-in advanced document editing and formatting tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does Word's Find and Replace have a 255-character limit?

Microsoft Word's built-in Find and Replace feature was historically designed for processing short strings. When a search or replacement string exceeds 255 characters, the native tool cannot process it, often requiring users to employ clipboard tricks or VBA macros.

What causes Run-time error 5941 in Word VBA?

Error 5941 indicates that 'The requested member of the collection does not exist.' In VBA macros, this typically happens when the code references a specific paragraph, table, or object index that isn't actually present in the current document structure.

Can I replace long text in Word without using VBA macros?

Yes. You can copy your long replacement text to your clipboard. Then, open the Find and Replace dialog, type your short search term in the 'Find what' box, and type ^c in the 'Replace with' box. This tells Word to replace the found text with your clipboard contents.

How do I ensure my macro ignores document formatting marks?

In your VBA code, you can adjust the range end by implementing the logic .End = .End - 1. This successfully excludes the final paragraph return mark, preventing the structural formatting from being accidentally overwritten during the text replacement.