Macro to copy a table from excel into word

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Fiddlercrab1

Thread Starter
Joined
Nov 11, 2004
Messages
61
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
 
Joined
Jul 29, 2001
Messages
21,334
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top