How to insert text into a word document in vba

Updated July 20, 2017

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.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jaime Avelar is a professional writer whose programming articles appear on various websites. He has been a software programmer since 2000. Avelar holds a Master of Science in information systems from the University of Texas at Arlington.