Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Insert chart into Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maynard - 10 Mar 2005 13:13 GMT
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
Helmut Weber - 10 Mar 2005 15:07 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.