Copy excel graph to word document and return to excel
Hi,
I'm looking for a way to copy a graph from Excel, go into an open word document (with or without a particular name), paste the graph using the paste special "Windows Metafile" option, and then return to excel to continue with the excel macro. Is this possible?
Thanks!
RE: Copy excel graph to word...
Hi,
Here's some solution.
Note: 1) Check in the VBE menu Tools -> References... whether Microsoft Word 12.0 Object Library is checked. 2) The code not handling the errors if they raise. Possible error: there is no open word document.
' ************************* ' ************************* '
Sub YourSubroutine()
' Your declarations
Dim oChart As Chart
Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document
' Your code
' Change the sheet and the chart index if necessary
Set oChart = Sheet1.ChartObjects(1).Chart
Set oWordApp = GetObject(, "Word.Application")
Set oWordDoc = oWordApp.ActiveDocument
oChart.CopyPicture
oWordDoc.Range(Start:=oWordApp.Selection.End).PasteSpecial _
DataType:=wdPasteMetafilePicture
' Your code
Set oWordDoc = Nothing
Set oWordApp = Nothing
Set oChart = Nothing
End Sub
' ************************* ' ************************* '
Best regards.