How to insert text into a word document in vba

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to insert text into a word document in vba
Insert text into Word using VBA in just a few steps. (word image by dinostock from

Microsoft Word is a word processing application that is part of the Office suite. VBA is commonly used to automate routine tasks in Office applications such as Word. If you're working with Excel you may need to transfer text from a spreadsheet to Microsoft Word. In a few simple steps you can create a function to add text to a Word document using VBA.

Skill level:

Other People Are Reading


  1. 1

    Open Microsoft Office 2007, click "Developer" tab and select "Visual Basic". Click "Tools", select "References" and check "Microsoft Word 12.0 Object Library. Select "OK".

  2. 2

    Type the following to create a function:

    Private Function insertTextToWord()

    Press "Enter".

  3. 3

    Type the following to create your variables:

    Dim wrdApp As Word.Application

    Dim wrdDoc As Word.Document

  4. 4

    Type the following to open Word and add a new document:

    Set wrdApp = CreateObject("Word.Application")

    wrdApp.Visible = True

    Set wrdDoc = wrdApp.Documents.Add

  5. 5

    Type the following to add text to your document:

    With wrdApp

    .Selection.TypeText Text:="This is text from Excel inserted into a new Word document."

    End With

    Execute your function.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.