I am using Excel VBA to open an existing Word document (based on directory and filename entered on Excel worksheet) and then copy and paste a table from active Excel workbook, leaving the Word document open for the user to manually arrange.
The code below works fine if Word is not already open but if Word is already open it will open the document but when it goes to paste it errors (Jumping to the error handler for document not found).
How can I pick the required Word document from multiple open Word documents to then paste to?
Sub Einsueb()
Dim wdApp As Object
Dim wdDoc As Object
Dim ws As String
Dim EinsuebPath As String
' x - Defined Cell Names , DFEinsueb , DFEinsuebDOC , DFEinsuebRng
On Error GoTo errHandler
EinsuebPath = ActiveSheet.Range("DFEinsueb").Value & ActiveSheet.Range("DFEinsuebDOC").Value ' x
Range("DFEinsuebRng").Select ' x
Selection.Copy
Set wdApp = CreateObject("Word.application")
wdApp.Visible = True
wdApp.Activate
Set wdDoc = wdApp.Documents.Open(FileName:=EinsuebPath)
' This is Word VBA code, not Excel code
Word.ActiveDocument.Bookmarks("New_Case").Range.Paste
' wdDoc.Close savechanges:=False
Set wdDoc = Nothing
' wdApp.Quit
Set wdApp = Nothing
' stop macro if error
exitHandler:
Exit Sub
errHandler:
MsgBox " Word Document not found" & vbNewLine & vbNewLine & _
" Check that correct Document name and directory" & vbNewLine & _
" have been entered"
Resume exitHandler
End Sub