Problem looping ChartObjects in a Com-dll

P

Peter T

My app loops all ChartObjects on a sheet two or more times. The first loop
reads a few properties for a few pre-checks and runs fine. The second loop
reads a lot more chart properties and makes changes to charts.

In the second loop when it get to setting a ref to the second chartobject
things go seriously wrong, typically with error no / description:
-2147417848 / Method '~' of object '~' failed

Stepping through -
For i = 1 to xlApp.ActiveSheet.ChartObjects.count
Set cht = xlApp.ActiveSheet.ChartObjects(i) ' i = 2

Looking at cht in locals most of the properties are not accessible (though a
small number are such as Name).

Everything is error handled and I can get back to my form and quit the app.
However when I next try and select a chart Excel crashes!

What's odd is this problem only occurs when the dll is run as a Com AND if
no charts had ever been selected on the sheet since the workbook was opened.
Had I first selected a chart (object) everything runs fine, whether or not a
chart was selected while running the app.

The same dll can be run as an Active-X. With this method there are no
problems at all! The only significant difference between running as a Com or
Active-X is how the app starts. As a Com it starts from the 'hooked' click
event of an Excel menu button. As an Active-X vba instanciates an entry
class in the dll which has a public proc' to set a ref to Excel and run the
app.

I doubt anyone can recreate this problem but wonder if anyone has come
across something similar or can shed any light.

Regards,
Peter T
 

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