logo
search
VBA & Macro Problems

How to Use Word VBA Macros to Remove Line Breaks and Reformat Images

Kushani NimanthikaKushani Nimanthika Sep 30, 2026 869 views

Question details

The user wants to create or troubleshoot a Word VBA macro to reliably remove manual line breaks and paragraph marks without negatively impacting image layouts and document formatting.

How to Remove Line Breaks and Reformat Text Using Word VBA Macros
Product
Word
Device & OS
not provided
Scenario
Reformatting a document heavily reliant on manual line breaks and empty paragraphs using VBA macros.
Observed behavior
Standard Find and Replace macros are removing unintended breaks because Word uses different character codes for paragraph marks and line breaks, and hidden spaces prevent empty paragraphs from being deleted.
Before you start

Before running any VBA macro, always test it on a duplicate copy of your document to prevent unintended cascading replacements that could alter essential text formatting or image anchors.

Solution 1Recommended

Differentiate Paragraph Marks (^13) and Manual Line Breaks (^11)

Modify your VBA macro to search for paragraph marks and manual line breaks separately using their specific character codes.

Word treats manual line breaks (inserted via Shift+Enter) differently than standard paragraph marks (inserted via Enter). Addressing them individually in your macro ensures precise text manipulation.

You can combine this with wildcard searches in VBA to match the specific characters immediately preceding the intended breaks.

1
Identify the target character codes

In your VBA editor or Find and Replace dialog, use ^13 to target standard paragraph marks and ^11 to target manual line breaks.

2
Configure the VBA Find parameters

Set up your macro to execute two separate Find and Replace operations: one that searches for ^11 and replaces it with a space, and another that targets ^13 where necessary.

3
Enable Wildcards in VBA

If you need to preserve characters before the break, ensure your macro sets 'MatchWildcards = True' so you can use pattern matching to skip or include preceding text.

Differentiate Paragraph Marks (^13) and Manual Line Breaks (^11)
Wildcard Matching: Using wildcards allows you to remove a paragraph mark followed immediately by a line break, replacing selected marks with a space while preserving the preceding character.
Efficient Text Formatting with WPS Writer

Easily Remove Line Breaks in WPS Writer Without Macros

WPS Writer provides a powerful, built-in Find and Replace tool with full wildcard and special character support. You can easily clean up line breaks and empty paragraphs visually without needing to write or debug complex VBA code.

  1. 1. Open the Find and Replace dialog: Open your document in WPS Writer and press Ctrl + H on your keyboard to launch the Replace tab.
  2. 2. Select the special character: Click the 'Special' button at the bottom of the dialog. From the list, select 'Manual Line Break' (^l) or 'Paragraph Mark' (^p) depending on what you want to remove.
  3. 3. Set the replacement criteria: Leave the 'Replace with' field blank if you want to delete the breaks entirely, or type a single space if you want to join the lines together.
  4. 4. Execute the replacement: Click 'Replace All' to instantly format your document. WPS Writer will notify you how many replacements were made.
100% compatible with Microsoft Word document formats (.docx)Intuitive Advanced Find and Replace tool with dropdowns for special charactersNo coding required to remove complex formatting or hidden line breaksLightweight application with a clean, familiar interface
microsoft office alternative - wps office

Frequently Asked Questions

What is the difference between ^13 and ^11 in Word macros?

In Word VBA, ^13 represents a standard paragraph mark (created by pressing Enter), which controls paragraph-level formatting. ^11 represents a manual line break (created by pressing Shift+Enter), which forces text to a new line without starting a new paragraph.

Why is my VBA macro failing to delete empty paragraphs?

Empty paragraphs often contain hidden formatting characters, such as trailing spaces or tabs, which prevent the macro from recognizing the paragraph as 'empty'. You must program the macro to search for and clear these hidden spaces before attempting to delete the paragraph mark.

How do I prevent my Find and Replace macro from altering image positions?

Images in Word are often anchored to specific paragraph marks. If a global wildcard replacement accidentally targets the paragraph mark anchoring an image, the image layout will break. Account for indentation and cascading paragraphs in your VBA code, and avoid blanket deletions of all ^13 characters.