Can't use 'Selection.TypeText' method when writing to Word document from Excel VBA

excel, ms-word, vba

Solution

Try this:

Sub WriteToWord()

Dim WrdApp As New Word.Application
Dim WrdDoc As Document
Dim WrdSel As Selection

WrdApp.Visible = True
Set WrdDoc = WrdApp.Documents.Add
Set WrdSel = WrdApp.Selection

WrdSel.TypeText "Test"

End Sub

You were pretty close with your code. The error you were having is that there is no `.Selection` property for `DestDoc`. You could have done it outside instead. However, your style is not best practice, so refer to my style above so you can identify exactly which is what. :)

Let is know if this helps.

Problem

I'm trying to write to a Word document from Excel VBA, and when I try using `.TypeText` method on `Selection` object, I get an error: "Object doesn't support this property or method." I've read somewhere that Excel VBA doesn't know that I'm referring to the Selection object in my Word document, so I tried the suggested solution, which was to try to do it in a `With` - `End With` block. Basically I tried this: ``` Set WrdApp = New Word.Application Set DestDoc = WrdApp.Documents.Add With DestDoc .Activate .Select .Selection.TypeText Text:="Test" End With ``` But it always reports the same error on the `.Selection.TypeText` line. Any help would be appreciated.

Original source