Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Word VBA New Line: Insert Line Breaks in Macros

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

A new line in Word VBA is created with vbCrLf, vbNewLine, or Chr(10) for a line feed, but the correct choice depends on whether you are writing text into a document or building a string for display. For most document text, use vbCrLf to insert a paragraph break; use vbLf or Chr(10) for a soft line break within a paragraph. The steps below show how to insert each type, avoid common errors, and troubleshoot when the new line does not appear as expected.

What You'll Need

  • Microsoft Word installed on Windows or Mac (the VBA editor is included; no extra download).
  • Macro security set to allow macros. In Word, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and choose "Disable all macros with notification" or "Enable all macros" for testing only.
  • Basic familiarity with opening the VBA editor (Alt+F11 on Windows, or Developer tab > Visual Basic). On Mac, use Tools > Macro > Visual Basic Editor.

Step-by-Step

  1. Open the VBA editor. In Word, press Alt+F11 (Windows) or go to Developer > Visual Basic (Mac: Tools > Macro > Visual Basic Editor). If the Developer tab is hidden, enable it in File > Options > Customize Ribbon. Menu labels can differ slightly by version, device, or region.
  2. Insert a new module. In the VBA editor, choose Insert > Module. This gives you a blank code window where you can write your macro.
  3. Create a simple macro to insert a paragraph break. Type the following code:
    Sub InsertParagraphBreak()
        Selection.TypeText Text:="First line" & vbCrLf & "Second line"
    End Sub
    vbCrLf is a carriage return plus line feed, which Word interprets as a paragraph mark (the same as pressing Enter). Run the macro with F5 or Run > Run Sub. The text will appear on two paragraphs.
  4. Insert a soft line break within a paragraph. Use vbLf (line feed only) or Chr(10):
    Sub InsertSoftBreak()
        Selection.TypeText Text:="First line" & vbLf & "Second line"
    End Sub
    This produces a manual line break (Shift+Enter) rather than a new paragraph. Note that vbCrLf in this context would create a paragraph break, not a soft break.
  5. Use vbNewLine for platform-independent code. vbNewLine resolves to vbCrLf on Windows and vbLf on Mac. For document text, prefer vbCrLf explicitly if you need a paragraph break on both platforms; vbNewLine may produce a soft break on Mac. Test on your target platform.
  6. Insert a line break using the InsertParagraphAfter method. You can also add a paragraph mark without building a string:
    Sub AddParagraphMark()
        Selection.InsertParagraphAfter
        Selection.TypeText Text:="New paragraph text"
    End Sub
    This is useful when you want to add a blank paragraph after the current selection.
  7. Write to a document range instead of the selection. For more control, use a Range object:
    Sub InsertIntoRange()
        Dim rng As Range
        Set rng = ActiveDocument.Range(0, 0)
        rng.Text = "Line one" & vbCrLf & "Line two"
    End Sub
    This inserts at the very start of the document. Adjust the range positions as needed.
  8. Check the result and save. Run the macro, inspect the document, and save your work. If the new line does not appear, see Troubleshooting below.

Common Mistakes

  • Using vbCrLf when you need a soft break. vbCrLf creates a paragraph mark, which may add spacing or affect styles. Use vbLf for a line break within a paragraph.
  • Confusing vbNewLine with vbCrLf. They are not always identical across platforms. If your macro must work on both Windows and Mac, test the output.
  • Forgetting to concatenate with &. In VBA, use & to join strings, not + (though + works for strings, & is safer and clearer).
  • Assuming Chr(13) alone creates a paragraph break. Chr(13) is a carriage return; Word may treat it as a paragraph mark, but vbCrLf is the standard and more reliable choice.
  • Not accounting for existing paragraph marks. If you insert text at a selection that already includes a paragraph mark, you may get extra blank lines. Use Selection.Collapse or adjust the range.

Tips

  • Use vbCrLf for paragraph breaks in document text; use vbLf for manual line breaks (Shift+Enter).
  • To insert a new line at the end of a document, use ActiveDocument.Content.InsertParagraphAfter then type your text.
  • When building strings for message boxes or debug output, vbCrLf is the conventional choice.
  • Use Debug.Print to inspect the exact characters in a string if the output looks wrong.
  • Always test macros on a copy of your document before running them on important files.

Troubleshooting

If the new line does not appear as expected, check these in order:

  1. Verify the macro ran. Add MsgBox "Done" at the end to confirm execution.
  2. Check the selection. If nothing is selected, Selection.TypeText inserts at the cursor. If the cursor is in a table cell, line breaks may behave differently.
  3. Inspect for hidden formatting. Turn on paragraph marks (Home > Show/Hide ΒΆ) to see whether you inserted a paragraph mark or a manual line break.
  4. Test with a simple string. Replace your text with "A" & vbCrLf & "B" to isolate the issue.
  5. Check for autoformat interference. Word's AutoFormat may convert straight quotes or other characters; this does not affect line breaks, but it can change text.
  6. If using vbNewLine on Mac, try vbCrLf explicitly to force a paragraph break.
  7. If the macro fails with an error, ensure the module compiles (Debug > Compile VBAProject) and that you are not missing references.

Frequently Asked Questions

What is the difference between vbCrLf and vbNewLine in Word VBA?

vbCrLf is always a carriage return plus line feed (Chr(13) & Chr(10)). vbNewLine is platform-dependent: on Windows it is the same as vbCrLf, but on Mac it is vbLf (Chr(10)). For consistent paragraph breaks, use vbCrLf.

How do I insert a line break without starting a new paragraph?

Use vbLf or Chr(10) in your string. This inserts a manual line break (Shift+Enter) within the same paragraph.

Why does my macro add an extra blank line?

You may be inserting a paragraph break when the selection already contains a paragraph mark, or you are using vbCrLf twice. Check the selection and use Selection.Collapse to avoid duplicating breaks.

Can I use Environment.NewLine in Word VBA?

No, Environment.NewLine is a .NET property and is not available in VBA. Use vbCrLf or vbNewLine instead.

How do I insert a new line at the end of a document?

Use ActiveDocument.Content.InsertParagraphAfter followed by Selection.TypeText or set a range to the end of the document and insert text.

Does Chr(13) work the same as vbCrLf?

Chr(13) is a carriage return only. Word may interpret it as a paragraph mark, but vbCrLf is the standard and more reliable choice for paragraph breaks.