PDA

View Full Version : Excel charts into an existing doc



juzzie
06-08-2011, 02:30 AM
Hi everybody, I'm a VBA basic userand I need help...
I need to copy (existing) excel-charts into a particular position of an existing word document. I can do it into a new doc, but not in the one I have already. here is my code until now:

Sub InsertXLChart()
Dim xlApp As Excel.Workbook
' Replace "XLfilename" with a complete path and file name
' for an Excel worksheet that includes a chart.
Set xlApp = GetObject("Z:\...\filename.xls")
' Activate the chart named Chart 1 in the workbook.
xlApp.ActiveSheet.ChartObjects(1).Activate
' Select the chart.
xlApp.ActiveChart.ChartArea.Select
' Copy the chart.
xlApp.ActiveChart.ChartArea.Copy
' same behaviour if defined:
'Dim WordApp As Word.Application
With Selection
Selection.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
Placement:=wdFloatOverText, DisplayAsIcon:=False
End With
Selection.ShapeRange.IncrementLeft 98.35
Selection.ShapeRange.IncrementTop -135.75
End Sub

thanks in advance..