Macro does not work inside Excel 2007

A

Andreas Wiechmann

Got a problem with my 2003 macro inside excel 2007.
When I start that macro I get the error message below (translated from
german):

"error-No.: 1004
description: application- or objectdefinition error
modul: vba project
area: AddChart
code area: 11"

Has anyone an idea?

Andreas
 
S

SeanC UK

Hi Andreas,

Can you please give the macro code? it is probably something that someone
could guess at, but if you give the code then we can be sure to give a better
answer.

Cheers,

Sean.
 
A

Andreas Wiechmann

Hi Sean,



thanks for your answer. In the meantime I've localized the malfunction.



Look at this:





++++++++++ >>>'.ChartGroups(1).SeriesCollection(arrPlotOrder(i -
1)).PlotOrder = i
arrColorIndex(i)



The instruction with the plus signs I have commented out and things are
working again.



But we have about one thousand of those files and no one is keen on changing
all included macros.



What do you think?



Regards



Andreas
 
S

SeanC UK

Hi Andreas,

I have had a look at this and the same thing is happening for me. I am not
entirely sure why at the moment, but I have found that selecting the chart
before attempting this line appears to prevent the problem. I will try to
look into this more and will let you know if I discover the reason. Hopefully
someone else has already addressed this and will comment here. In the
meantime, try adding a line like this and see if it helps:

ActiveSheet.ChartObjects(1).Select

Obviously you will need to use the ChartObject index for your chart,

Once it has been selected the code appears to work. I found this
accidentally when I noticed that the code worked after I opened the workbook
in 2007 and selected the graph properties, then going back to the code and
saw that it worked, even though I hadn't changed any of the graph properties.
But then going back to 2003 caused the problem to occur there. However,
selecting the graph properties in 2003 again prevented the problem, but
reintroduced it to 2007! Therefore I added the select line to the macro and
it appears to run now in both.

As I said, I am not entirely sure why this is happening, and if I get time I
will look into it further. Let me know if this works for you. In my opinion,
if this works then it is a temporary workaround, knowing why this happens is
more important so that the code can be written to always work.

I imagine that you will have to be changing code in your macros, either to
add some lines or to comment out your line.

Either way, if you do find that you need to be changing code in 1000s of
workbooks then I would consider looking into writing something that can
automate this process; a bit more complicated, but in the long run it may
save you time and give you a method to update the workbooks in future, should
you need to do so again.

I hope this helps, and if I do find out why then I shall let you know, and
I'll be watching this post to see if anyone else can give an explanation.

Sean.
 

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