How to insert text into a word document in vba

Written by jaime avelar | 13/05/2017
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.

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".

Type the following to create a function:

Private Function insertTextToWord()

Press "Enter".

Type the following to create your variables:

Dim wrdApp As Word.Application

Dim wrdDoc As Word.Document

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

Set wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Add

Type the following to add text to your document:

With wrdApp

End With

Execute your function.

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