Insert chart into Word

M

Maynard

I posted this in the Excel programming NG, but to no avail...thought I'd try
it here.

I would like to have a macro (I'm actually writing it in Excel) that would
take the active chart and paste it into an open Word document at the current
location of the cursor. Unfortunately, I'm much more familiar w/ the Excel
object model than the Word object mode. I have the following code, but can't
quite figure out what object(s) need to go where the XXXX is. Oh, and I'm
more concerned about getting this to work rather than what's better
(imagefile, metafile, etc). Thanks in advance!

Sub PortToWord()

Dim WrdDoc As Word.Document

Set WrdDoc = Word.ActiveDocument
ActiveChart.Copy
WrdDoc.Range.PasteSpecial DataType:=wdPasteEnhancedMetafile,
DisplayAsIcon:=False

End Sub
 
H

Helmut Weber

Hi Maynard,

this one works for me:
' ---
ActiveChart.ChartArea.Copy
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Set oWrd = New Word.Application
Set oDoc = oWrd.Documents.Open("c:\test\test.doc")
oWrd.Visible = True
oWrd.Selection.PasteSpecial
' ---
You might want to place the selection
beforehand where you want it to be,
maybe instead of the selection, you'd
like to use a bookmark. Or is Word
already active and the target document open?

Then this should be sufficient:
' ---
ActiveChart.ChartArea.Copy
Dim oWrd As Word.Application
Set oWrd = GetObject(, "Word.Application")
oWrd.Selection.PasteSpecial
' ---

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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