Bug with Chart.Name?
The email with a link to the workbook will be on the way soon. The week
was too wild to get it to you sooner.
I did not try the .Shapes loop yet, but don't have much hope for it.
Thanks,
bart13
Peter T;678958 Wrote: [color=blue][i]
I really would expect both the "for i = 1 to .chartobjects.count" and
the
For each shp in .Shapes loop (with if msoChart test) to work
correctly.
Possibly there's something else in your own code at fault, or some
other bug
that we have all missed.
If you like you can send me a zipped stripped down non-sensitive
version of
what you have. Make a copy of your book, prune as much as possible in
terms
of data, charts, sheets and not least code; leaving just enough to
demonstrate the problem.
Regards,
Peter T
pmbthornton gmail com
"bart13" wrote in message
...-
Yes - very much so. The straight loop (as in "for i = 1 to
activesheet.chartobjects.count" ) has wrong results, just like
every
other attempt and regardless of whether the if test was being used
or
not. There are 6 charts on the tab, only three show up in both the
actual text file and the debug print statement.
No matter what the code is, charts are being skipped.
To state it another way, Pict.Name and Pict.Chart.Name return the
exact
same matching values - every time. But both only return three names
and
there are six charts, and all six have unique names in the name box.
No matter if I look at the output in the text file or from the debug
print statement, its the same issue. Six charts in the tab, only
three
recognized.
And I do betray my ancient status as a coder. The last time I did
any
Basic coding, there was no such thing as a for each loop so the "for
i
= 1 to ..." is normal to me.
I did double check the name box again for all six charts, and all
the
names are both unique and do not contain punctuation either (unless
an
underscore is considered punctuation).
I'm obviously missing something since it appears you're saying I
have
dupe names, but I have no way of which I'm aware to change the
duplicate ones nor is there any code that I can run which will
distinguish the dupes.
The only way that works on new copied charts is not to change the
name
but rather hard code it into a select case set of statements based
on
the "Chart ###" name.
Are you saying that this is expected behavior and an open and old
bug
(or something similar), and that I should just continue to do the
hard
coding and work around? I'm not trying to be accusatory, just in
case.
Regards,
bart
Peter T;678438 Wrote:--
I did try the normal loop based on max chart count and the
results-
were--
the same. Sorry, I just didn't post it since there was no new
data.--
I assume by "the normal loop" you mean
for i = 1 to activesheet.chartobjects.count
although most people might consider "For..Each" as the "normal" way
to
loop
objects.
Are you absolutely sure the dubug results are different with the
different
methods of looping.
Here's yet another way you can loop your charts
Sub test()
Dim shp As Shape, chtObj As ChartObject, cht As Chart
For Each shp In ActiveSheet.Shapes
If shp.Type = msoChart Then
i = i + 1
Set chtObj = shp.DrawingObject
Set cht = chtObj.Chart
Debug.Print i, chtObj.Name, cht.Name
End If
Next
End Sub
I would not expect this to work differently to a For i = 1 to
..Chartobjects.Count loop
From what you have described about chartobjects having been renamed
and
copied I'm not surprised your For Each loop has failed to reference
all
correctly.
I know it might seem odd but actually, as your subject line
suggests,
there
can be a bug of sorts when looping For Each with any object type at
the
'DrawingObject' level; of which ChartObject is a sub type. Apart
from
picking up the wrong object, in the case of duplicate names, names
that
include punctuation can be missed completely. Remember, we are
talking
about ChartObject name here, which is not (normally) same as
chartobject.Chart.Name (though chartObject & Shape names will be
the
same).
Regards,
Peter T
"bart13" wrote in message
...-
It was meaningful to me in the sense that it displayed exactly
what I
was expecting. Charts are just plain being missed in the loop,
no
matter how the loop is constructed or even if the if statement
is
removed. The ChartObjects are getting corrupted when renamed, and
its
pretty consistent.
I did try the normal loop based on max chart count and the
results-
were-
the same. Sorry, I just didn't post it since there was no new
data.
Thanks for clarifying on the grouping. I've seen it on one of
the
properties menus but never took it any further since I seldom use
any
extra chart elements like text boxes, etc.
I hope Mr. Peltier jumps in with an idea or two. I'm at my wits
end.
It seems that every time I copy a chart now and then rename it,
the
ChartObject gets corrupted and will never again be seen by any
loop.-
If-
I don't rename it and just translate the "Chart ###" name to my
own
filename in a select case statement, all is well.
I've even tried deleting about 30 of the extra charts in the
main-
chart-
tab on the theory that there's some unknown limit I've exceeded,
but-
it-
made no difference.
bart13
-
-
--
bart13-
--
bart13
|