Adding Excel charts to PowerPoint presentation in Office 2003

T

trooper665

In Office 2000 this code worked perfectly:

Dim xlCurrChart As Excel.Chart
Dim xlBook As Excel.Workbook
Dim pptShape As PowerPoint.Shape

Set pptShape = rpptTarget.Shapes.AddOLEObject(Width:=fDefaultWidth,
Height:=fDefaultHeight, ClassName:="Excel.Sheet")

Set xlBook = pptShape.OLEFormat.Object
Set xlCurrChart = xlBook.Charts.Add()

But now testing this with Office 2003, the last line raises an error. The
weird thing is that this code is in a loop and the error is only raised the
first time that this code fires. After the first loop, the code no longer
raises any errors and works fine.

Any ideas?
 
B

Brian Reilly, MVP

I ran into a similar error years ago which would randomly throw an
error like this. I never did figure it out but the workaround was to
capture the error and go to the errorhandler and verify the error
number and if it was this error to go back and try again. Something
like (not tested, just typing logic here)

Sub test()
On Error GoTo errorhandler
TryAgain:
MsgBox "Error" 'just to
'some code that might throw this error

Exit Sub

errorhandler:
Select Case Err
Case Is = 42 'the Err value
GoTo TryAgain
Case Else
Exit Sub
End Select
End Sub

Brian Reilly, MVP
 
T

trooper665

Unfortunately, the error doesn't seem to be trappable. This problem is
really driving me nuts. The DoEvents suggestion didn't work either.

Thanks,
Jeff
 
T

trooper665

There is error handling in the subroutine that this code is in, but the error
doesn't get handled there. When the error actually raises this is the
message: Error number: - 2147417851 method '~' of object '~' failed. Which
isn't very helpful. Hope that makes sense.

Thanks,
Jeff
 
T

trooper665

Hi Steve,

Yes, it literally says method '~' of object '~' failed. Definitely the
worst error message I have ever encountered.

Thanks,
Jeff

Steve Rindsberg said:
There is error handling in the subroutine that this code is in, but the error
doesn't get handled there. When the error actually raises this is the
message: Error number: - 2147417851 method '~' of object '~' failed. Which
isn't very helpful. Hope that makes sense.

It literally says " method [tilde character]"?
If not, what are the specific objects and methods mentioned?
Thanks,
Jeff

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
T

trooper665

Yeah, unfortunately I tried that already and came away with nothing.

I could understand if Microsoft decided to change the parameters to one of
the calls or something, but for it to work on subsequent calls is really just
odd.

Thanks for trying to help,
Jeff

Steve Rindsberg said:
Yes, it literally says method '~' of object '~' failed. Definitely the
worst error message I have ever encountered.

There sure isn't much room for making it more useless.

I plugged the exact error string you give below (thanks for typing it verbatim) into
Google and got a fair number of hits, most of which seem database releated (SQL, MDAC and
the like). Nothing connected to PPT directly, so no bells are going off at this end.
You might want to do the same to see if anything triggers the Aha experience for you.

Thanks,
Jeff

Steve Rindsberg said:
There is error handling in the subroutine that this code is in, but the error
doesn't get handled there. When the error actually raises this is the
message: Error number: - 2147417851 method '~' of object '~' failed. Which
isn't very helpful. Hope that makes sense.

It literally says " method [tilde character]"?
If not, what are the specific objects and methods mentioned?


Thanks,
Jeff

:

Unfortunately, the error doesn't seem to be trappable. This problem is
really driving me nuts. The DoEvents suggestion didn't work either.

Hmm. Then to be more precise, it doesn't raise an error in the usual VB/VBA
sense, else it would be trappable, but it throws up some kind of error message
box? What's the specific error message?



Thanks,
Jeff

:

I ran into a similar error years ago which would randomly throw an
error like this. I never did figure it out but the workaround was to
capture the error and go to the errorhandler and verify the error
number and if it was this error to go back and try again. Something
like (not tested, just typing logic here)

Sub test()
On Error GoTo errorhandler
TryAgain:
MsgBox "Error" 'just to
'some code that might throw this error

Exit Sub

errorhandler:
Select Case Err
Case Is = 42 'the Err value
GoTo TryAgain
Case Else
Exit Sub
End Select
End Sub

Brian Reilly, MVP


On Fri, 30 Sep 2005 09:55:05 -0700, "trooper665"

In Office 2000 this code worked perfectly:

Dim xlCurrChart As Excel.Chart
Dim xlBook As Excel.Workbook
Dim pptShape As PowerPoint.Shape

Set pptShape = rpptTarget.Shapes.AddOLEObject(Width:=fDefaultWidth,
Height:=fDefaultHeight, ClassName:="Excel.Sheet")

Set xlBook = pptShape.OLEFormat.Object
Set xlCurrChart = xlBook.Charts.Add()

But now testing this with Office 2003, the last line raises an error. The
weird thing is that this code is in a loop and the error is only raised the
first time that this code fires. After the first loop, the code no longer
raises any errors and works fine.

Any ideas?



-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================





-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 

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