Error when trying to copy Excel Chart into Word Doc -Method 'Activ

P

Pete

Office2003 SP2

I am getting this error when I use the code below.
-2147417851
Method 'Activate' of object 'ChartObject' failed

The code is intended to copy a chart from sheet1 of the XL workbook to a
bookmark in the current Word doc.
You will see that I have tried some diagnostic code and I get the correct
answers to those commands.

Can anyone suggest any way of resolving this?

Pete


Sub InsertXLChart()
Dim xlapp As Excel.Workbook
Dim chrt As Excel.ChartObject
On Error GoTo errhandle
Set xlapp = GetObject("c:\testbk.xls")

' debug code (shows correct info)
' MsgBox xlapp.ActiveSheet.Name
'For Each chrt In xlapp.ActiveSheet.ChartObjects
' Debug.Print chrt.Name
' Next chrt

' Activate the first chart in the workbook. (tried Both methods)
xlapp.ActiveSheet.ChartObjects("Chart 1").Activate
'************error here*********
' xlapp.ActiveSheet.ChartObjects(1).Activate
' Select the chart.
xlapp.ActiveChart.ChartArea.Select
' Copy the chart.
xlapp.ActiveChart.ChartArea.Copy

' go to the position in Word doc
Selection.GoTo What:=wdGoToBookmark, Name:="Rng2"

' The wdPasteOLEObject constant will insert the chart as an
' embedded object, and the wdInLine constant will insert the
' chart on the text layer and not the drawing layer.
Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject,
Placement:=wdInLine
exitsub:
' Close the instance of Excel.
xlapp.Close
Set xlapp = Nothing
Exit Sub
errhandle:
Debug.Print Err.Number
Debug.Print Err.Description
Resume exitsub
End Sub
--
 

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