Marco Excel chart to active word document (Office 2010)

Joined
May 19, 2011
Messages
5
Reaction score
0
Hi,

i want a macro that can copy an actively selected excel chart and copy it to the cursor position of an open word doc, ive tried to use the following code but it seems to come up with errors, any solutions?
Code:
Sub ChartToDocument()
' Set a VBE reference to Microsoft Word Object Library
 
Dim WDApp As Word.Application
Dim WDDoc As Word.Document
 
' Make sure a chart is selected
If ActiveChart Is Nothing Then    
    MsgBox "Please select a chart and try again.", vbExclamation, _        
    "No Chart Selected"
Else    
' Reference existing instance of Word    
Set WDApp = GetObject(, "Word.Application")    
' Reference active document    
Set WDDoc = WDApp.ActiveDocument       
 
' Copy chart as a picture    
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _       
Format:=xlPicture    
 
' Paste chart at cursor position    
WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _        
    Placement:=wdInLine, DisplayAsIcon:=False    
 
' Clean up    
Set WDDoc = Nothing    
Set WDApp = Nothing
End If

End Sub
 
Last edited:
Joined
May 19, 2011
Messages
5
Reaction score
0
SOLVED

pretty silly, just need to make sure you select Microsoft word 14.0 object library under

tools>references
 
Last edited:

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