Tech Support Guy banner
Status
Not open for further replies.
1 - 2 of 2 Posts

·
Registered
Joined
·
61 Posts
Discussion Starter · #1 ·
Hello,

I have managed to write a macro that copies a table from excel into a new document in word, here is the code:

Sub controlword()

Dim appwd As Word.Application

Set appwd = CreateObject("word.application.9")

appwd.Visible = True

appwd.Documents.Add

Set wdApp = New Word.Application

Range("a1:j7").Copy

appwd.Selection.Paste

End Sub


I would like to make it so that the table copies into word NOT into a new document but into any open document at the location of the cursor...

Could anybody help me out with the code for this...

Thanks
 

·
Registered
Joined
·
21,334 Posts
You need to Set appwd to use the currently open Word Document not CreateObject.

Sub Controlword()

Dim Appwd As Object

Set Appwd = GetObject(, "Word.Application")

Set wdApp = Appwd.ActiveDocument

Range("a1:j7").Copy

Appwd.Selection.Paste

End Sub


I didn't test for the cursor location.
 
1 - 2 of 2 Posts
Status
Not open for further replies.
Top