Excel Range In Word

P

Paul W Smith

I wish to paste a named range from Excel into a Word Document using VBA.
From Excel I have created a Word document as an object, but cannot
understand how to use any of the Word VBA code I have recorded.

In Excel I can easily reference the named range I require to insert, but how
I utilise this to paste it into the Word document I have created has me
scratcjing my head.

Recording the paste operation in Word gives:

Selection.PasteExcelTable False, False, False

All I am trying to to is paste a number of Excel ranges into a Word
document, does anyone have any code whioch might help me.

PWS
 
T

Tony Jollans

So, if you take your recorded code and qualify it with te Word object ...

(YourWordObject).Selection.etc

what happens?
 
D

Dan R.

Paul,

Try this:

Sub CopyToWord()
'must have a reference to the word object library
Dim wdApp As Word.Application
Dim ws As Worksheet
Dim wdDoc As Word.Document
Set wdApp = CreateObject("Word.application")
Set wdDoc = wdApp.Documents.Add

For i = 1 To Names.Count
ActiveSheet.Range(Names(i)).Copy
wdDoc.Paragraphs(wdDoc.Paragraphs.Count) _
.Range.InsertParagraphAfter
wdDoc.Paragraphs(wdDoc.Paragraphs.Count) _
.Range.Paste
Next i

wdApp.ActiveDocument.Save
wdDoc.Close
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top