You insert text in Word VBA with the InsertAfter and InsertBefore methods on a Range or Selection object. The shortest working line is Selection.InsertAfter "Your text here", which drops text at the cursor position and is the fastest way to prove your macro runs. The more reliable pattern for repeatable work is to define a Range, collapse it to the insertion point you want, and insert there, because that does not depend on where the user's cursor happens to be when the macro fires.

Everything below assumes the desktop version of Word for Windows or Mac. VBA is not available in Word for the web or in the mobile apps, so if a step does not match what you see, check that you are in the full desktop application.

What You'll Need

  • A desktop install of Microsoft Word (Windows or Mac). VBA does not exist in Word for the web, iPad, iPhone or Android, and macros cannot run there.
  • The Developer tab visible, or an existing document already saved as .docm. If the Developer tab is missing, open File > Options > Customize Ribbon, tick Developer in the right-hand list, and click OK. On Mac the equivalent is Word > Preferences > Ribbon & Toolbar.
  • A document you are happy to test in. Run macros on a copy until you are confident, because a bad loop can insert thousands of lines before you can stop it.
  • Basic comfort with the VBA editor: press Alt+F11 on Windows, or Option+F11 on Mac, to open it.

Step-by-Step

  1. Create a module. In the VBA editor, look at the Project Explorer on the left. Right-click your document's project, choose Insert > Module. A blank code window opens. A standard module is the right home for text-insertion helpers; code placed in ThisDocument only runs through document events.
  2. Start with the simplest insertion. Type this procedure: Sub InsertSimple()
        Selection.InsertAfter "Hello from VBA."
    End Sub
    Place your cursor where you want the text in the document, then press F5 inside the editor to run it. The text appears at the insertion point and the cursor ends up after it.
  3. Insert at a fixed location instead of the cursor. Cursor position is fragile, so most real macros use a Range. This example appends a line at the very end of the document body: Sub InsertAtEnd()
        Dim rng As Range
        Set rng = ActiveDocument.Content
        rng.Collapse wdCollapseEnd
        rng.InsertAfter "Closing paragraph." & vbCr
    End Sub
    wdCollapseEnd shrinks the range to a zero-width point at its end, so nothing existing is overwritten.
  4. Insert before the start of the document. Swap the collapse direction: rng.Collapse wdCollapseStart, then call rng.InsertBefore "Draft - ". InsertBefore pushes text in front of the range and keeps what was already there.
  5. Insert a whole paragraph with formatting. InsertAfter inherits the formatting of the surrounding text. To control it, set properties on the range first: rng.Bold = True, rng.Font.Size = 14, rng.ParagraphFormat.Alignment = wdAlignParagraphCenter, then insert. For multi-paragraph text, end each paragraph with vbCr and start the next range insertion after that character.
  6. Insert at a bookmark. If you have a bookmark named ClientName in the document, ActiveDocument.Bookmarks("ClientName").Range.Text = "Acme Ltd" replaces the bookmark's content with your text. Use a bookmark when the target position must move as the document grows; it is far more stable than counting paragraphs.
  7. Insert text from another file. rng.InsertFile "C:\\Docs\\clause.txt" pulls a whole file in at the range. For a Word document, add Range:= arguments if you only want a named bookmark from it, for example rng.InsertFile "C:\\Docs\\terms.docx", Range:="Liability".
  8. Save as a macro-enabled document. Close the editor and use File > Save As, choosing Word Macro-Enabled Document (.docm). A plain .docx discards the VBA project, and you will lose the code on the next save.

Common Mistakes

The most frequent problem is relying on Selection without checking where the cursor is. A user clicking in the header, a table cell, or another open document changes what ActiveDocument and Selection refer to, so the text lands somewhere unexpected. Prefer an explicit Range tied to a known document object.

Second, forgetting to collapse the range. Calling InsertAfter on an un-collapsed range replaces the selected content instead of adding around it, which silently deletes text. Always collapse first unless replacement is what you intend.

Third, forgetting vbCr. Inserted text runs into the previous paragraph, so two sentences merge. Fourth, saving as .docx and losing the module. Fifth, writing to a protected document without checking ActiveDocument.ProtectionType; the macro fails with a permission error that looks like a code bug but is a document setting.

Tips

  • Use ActiveDocument.Range(start, end) with character positions when you know exact offsets, and bookmarks or Find when you do not.
  • With ... End With blocks keep formatting lines readable when you set several properties before inserting.
  • To insert at a found word, run Find on a range, then collapse that found range to its end and insert after it.
  • Turn off Application.ScreenUpdating during loops that insert many pieces; it makes the macro much faster and looks tidier.
  • Name your macros something descriptive. Word lists every public procedure in the Macros dialog, and Macro1 through Macro9 becomes unusable fast.
  • Test with a copy of the document and a backup. Insert loops have no built-in undo step for the whole run.

Troubleshooting

Text appears in the wrong place. Check for a stray selection before the insertion line. Insert Debug.Print Selection.Start to see where the cursor really is when the macro runs.

Existing text vanishes. You inserted into an un-collapsed range. Add a Collapse call before the insert.

"This command is not available" or a permission error. The document may be protected, or the file may be read-only after opening from email or a network share. Check the document's protection setting and save a local copy first.

Nothing happens at all. Macros may be disabled. Look at the Trust Center settings in File > Options > Trust Center > Trust Center Settings, and confirm the document is in a trusted location or has been enabled when prompted. On Mac, check Word > Preferences > Security.

The code vanished after saving. The file is a .docx. Save as .docm and reopen it.

If that did not work: close Word fully and reopen, make sure no other Word windows are open that might be holding the active document, and re-check that your code sits in a standard module rather than behind a form or in ThisDocument.

Frequently Asked Questions

What is the difference between InsertAfter and InsertBefore?

InsertAfter adds text at the end of a range or selection; InsertBefore adds it at the start. Both expand the range to include the new text when applied to a multi-character range.

How do I insert text at the very beginning of a document?

Use ActiveDocument.Range.InsertBefore "Your text". That targets the whole document and inserts at offset zero.

Can I insert text without using the clipboard?

Yes. These methods write directly to the document; the clipboard is never touched, so any content you had copied stays intact.

How do I add a line break rather than a new paragraph?

Use vbCr for a paragraph mark and vbVerticalTab, or Chr(11), for a manual line break within the same paragraph.

Why does InsertAfter replace my text instead of adding it?

The range is not collapsed. Call Collapse first so the range becomes a single insertion point.

Does this work in Word for the web?

No. VBA is only available in the desktop versions of Word for Windows and Mac. Web and mobile versions cannot run macros.