How to Fix the Too Many Line Continuations Error in Word VBA
Question details
The user encounters a compilation error in Word VBA due to exceeding the maximum allowed line-continuation characters when assigning large blocks of text, which also sometimes results in overwritten bookmark content.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Writing VBA macros to insert large blocks of text or conditionally append multiple strings into a specific Word document bookmark.
- Observed behavior
- A "Too many line continuations" error occurs during code compilation. Additionally, assigning values via multiple direct statements overwrites the existing bookmark text instead of appending to it.
Before modifying your VBA code, save a backup copy of your Word macro-enabled document (.docm) to prevent accidental loss of your original logic and bookmark structures.
Use String Variables to Build Text Chunks
Instead of using dozens of underscores to continue a single line of code, concatenate your text step-by-step using a String variable to bypass the limitation.
VBA limits the number of consecutive line-continuation characters (typically 24 underscores) in a single logical statement. Attempting to concatenate massive strings in one go will trigger an error.
Breaking the assignment into multiple separate variable assignments completely bypasses this compiler limit while significantly improving the readability of your code.
In your VBA editor, type `Dim strContent As String` at the beginning of your subroutine to hold your text block.
Assign the first part of your text: `strContent = "First paragraph of text. "`. On a new line, append the next block by typing `strContent = strContent & "Second paragraph."`.
Continue using the `strContent = strContent & "..."` pattern inside your `If...Then` statements or loops to build the complete string dynamically without relying on the line-continuation character (`_`).

Safely Assign Built Strings to Bookmarks
Use a Range object to insert your concatenated string into a Word bookmark and recreate the bookmark to prevent it from being permanently deleted.
Optimize Control and Variable Naming Conventions
Prevent unexpected VBA conflicts by avoiding reserved keywords and giving built-in controls unique, descriptive names.
Write and Run VBA Macros Seamlessly in WPS Office
WPS Office provides robust native support for macros and VBA scripting, allowing you to run, edit, and debug your automated workflows effortlessly.
- 1. Open WPS Writer: Launch WPS Writer and open your macro-enabled document.
- 2. Access Developer Tools: Navigate to the 'Developer' tab on the top ribbon menu to access macro features.
- 3. Open VBA Editor: Click on 'Visual Basic' or 'Macros' to open the editor and implement your string concatenation code.

Frequently Asked Questions
What is the maximum number of line continuations allowed in VBA?
In Visual Basic for Applications, you are limited to a maximum of 24 consecutive line-continuation characters (the underscore `_`) in a single logical statement. Exceeding this limit will trigger a "Too many line continuations" compile error.
Why does my bookmark disappear after I insert text via VBA?
When you assign a new string value to a bookmark's Range object (for example, `bmRange.Text = "New Text"`), the original text and the bookmark boundary itself are overwritten and destroyed. You must redefine the bookmark using `Bookmarks.Add` after inserting the new text.
Can I append text directly to a bookmark without deleting it?
You can append text directly by inserting it after the bookmark's range using the `Range.InsertAfter` method. However, if you want the new text to be contained entirely inside the bookmark's boundary for future updates, replacing the text and recreating the bookmark is the most reliable method.




