Word VBA New Line: Insert Line Breaks in Macros
In this article
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
- 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.
- Insert a new module. In the VBA editor, choose Insert > Module. This gives you a blank code window where you can write your macro.
- Create a simple macro to insert a paragraph break. Type the following code:
Sub InsertParagraphBreak() Selection.TypeText Text:="First line" & vbCrLf & "Second line" End SubvbCrLfis 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. - Insert a soft line break within a paragraph. Use
vbLf(line feed only) orChr(10):
This produces a manual line break (Shift+Enter) rather than a new paragraph. Note thatSub InsertSoftBreak() Selection.TypeText Text:="First line" & vbLf & "Second line" End SubvbCrLfin this context would create a paragraph break, not a soft break. - Use
vbNewLinefor platform-independent code.vbNewLineresolves tovbCrLfon Windows andvbLfon Mac. For document text, prefervbCrLfexplicitly if you need a paragraph break on both platforms;vbNewLinemay produce a soft break on Mac. Test on your target platform. - Insert a line break using the
InsertParagraphAftermethod. You can also add a paragraph mark without building a string:
This is useful when you want to add a blank paragraph after the current selection.Sub AddParagraphMark() Selection.InsertParagraphAfter Selection.TypeText Text:="New paragraph text" End Sub - Write to a document range instead of the selection. For more control, use a
Rangeobject:
This inserts at the very start of the document. Adjust the range positions as needed.Sub InsertIntoRange() Dim rng As Range Set rng = ActiveDocument.Range(0, 0) rng.Text = "Line one" & vbCrLf & "Line two" End Sub - 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
vbCrLfwhen you need a soft break.vbCrLfcreates a paragraph mark, which may add spacing or affect styles. UsevbLffor a line break within a paragraph. - Confusing
vbNewLinewithvbCrLf. 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, butvbCrLfis 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.Collapseor adjust the range.
Tips
- Use
vbCrLffor paragraph breaks in document text; usevbLffor manual line breaks (Shift+Enter). - To insert a new line at the end of a document, use
ActiveDocument.Content.InsertParagraphAfterthen type your text. - When building strings for message boxes or debug output,
vbCrLfis the conventional choice. - Use
Debug.Printto 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:
- Verify the macro ran. Add
MsgBox "Done"at the end to confirm execution. - Check the selection. If nothing is selected,
Selection.TypeTextinserts at the cursor. If the cursor is in a table cell, line breaks may behave differently. - Inspect for hidden formatting. Turn on paragraph marks (Home > Show/Hide ΒΆ) to see whether you inserted a paragraph mark or a manual line break.
- Test with a simple string. Replace your text with
"A" & vbCrLf & "B"to isolate the issue. - 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.
- If using
vbNewLineon Mac, tryvbCrLfexplicitly to force a paragraph break. - 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.