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
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()
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:
.Selection.TypeText Text:="This is text from Excel inserted into a new Word document." .Selection.TypeParagraph
Execute your function.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for