Hello,
I usually only work in Excel, this is the first time I am trying to output to Word. As part of a larger macro run from Excel which will ultimately find and paste data into a new Word doc, I found a number of relevant threads here and was able to cobble together some code which mostly works. The part that isn't working is below. It's giving me a 438 run time error on the TypeText line. I get the same error when I run the code below from a macro run from Word. Microsoft Word 15.0 Object Library has been checked in References. I've tried other methods to specify the text string, such as omitting the "Text:=" and putting the string in parentheses, to no avail. I suspect the problem is a simple one having to do with the word document object, but hopefully someone more knowledgeable can tell me the fix. Thanks for your help.
I usually only work in Excel, this is the first time I am trying to output to Word. As part of a larger macro run from Excel which will ultimately find and paste data into a new Word doc, I found a number of relevant threads here and was able to cobble together some code which mostly works. The part that isn't working is below. It's giving me a 438 run time error on the TypeText line. I get the same error when I run the code below from a macro run from Word. Microsoft Word 15.0 Object Library has been checked in References. I've tried other methods to specify the text string, such as omitting the "Text:=" and putting the string in parentheses, to no avail. I suspect the problem is a simple one having to do with the word document object, but hopefully someone more knowledgeable can tell me the fix. Thanks for your help.
VBA Code:
Dim WdApp As Word.Application
Set WdApp = New Word.Application
WdApp.Visible = True
Dim wdDoc As Word.Document
Set wdDoc = WdApp.Documents.Add
wdDoc.Content.Select
wdDoc.Selection.TypeText Text:="Test"