Hi. How to write to a Word document which is open already?
I want to paste from Excel to Word, and the file may already exist or not. By searching existing threads I have solved this for creating a new file, for newly opening an existing file, but I don´t succeed when the document is opened by Word already.
Here´s some simplified code:
Sub wdTest() Dim WordApp As Object ' same behaviour if defined: 'Dim WordApp As Word.Application Dim WDoc As String Dim myDoc As String myDoc = "myTest" WDoc = ThisWorkbook.Path & "\" & myDoc & ".doc" a = MsgBox("Doc already opened?", vbYesNo) If a = vbYes Then ' this gives an error Set WordApp = GetObject(WDoc, "Word.Application") Else ' this works fine Set WordApp = CreateObject("Word.Application") WordApp.Documents.Open WDoc End If WordApp.Visible = True End Sub
So the name WDoc of the document seems to be o.k. as it works with Open - but it does not work with GetObject.
Thanks a lot.