Link to home
Start Free TrialLog in
Avatar of dlmille
dlmilleFlag for United States of America

asked on

Getting Defined name values while active sheet is chart tab

I'm getting invalid results when I try to interrogate a defined name when the active sheet is a chart tab.

I was using Evaluate(definedName) to get a non-range value.

What is the proper way to retrieve value from Defined Names while the active tab is a chart sheet?

Cheers,

Dave
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Try this:

ThisWorkbook.Range("DefinedName").Value

Kevin
Avatar of dlmille

ASKER

The Defined name contains a text string which cannot be referenced with the Range method.  One of the msn developer help pages suggested using Evaluate.  That works from the debugger, but its not working in the macro code associated with the chart calculate event.  What happens on initialization (when I debug print the outcome), it prints the string data I have at that defined name, but then the event no longer works afterward.  I believe the Evaluate is messing it up.  I need another way to access the defined name values than Evaluate.

Dave
All names can be accessed with the Range method. However, I was incorrect above - the Range method is not exposed as path of the Workbook class. You have to use the Names collection:

   Evaluate(ThisWorkbook.Names.Item("DefinedName").Value)

Kevin
Avatar of dlmille

ASKER

No Joy - doesn't even work in the debug window.  I'm sure you tested this.  I'll create a blank workbook with this simple command and we can play with that...

see pic,

Dave
Picture1.png
Yes, I did test it.

What, exactly, is the value of the defined name?

Kevin
Avatar of dlmille

ASKER

you can see it on the print screen.  WHen I did debug.print [definedName] it displayed just below.  Its a text string...

Dave
Avatar of dlmille

ASKER

Here you go.  I pared this app down to the minimum.

Its failing on the sub eventFixMyChart, in the fixMyChart module.  I've indicated in the comments where, but its where I'm trying to evaluate the value of what's stuck in the range name...  _chartwhatever_LabelRange_Settings <- Trying to get contents in a name that looks like this...

Dave
test.xlsm
I tried to reproduce and can't. I used 2007 with a chart sheet active.

Kevin
Avatar of dlmille

ASKER

Well, hopefully what I sent you will enable that.  Note the debug.print of the data only kicks off once, then after that the calculate event never pushes it to this routine again.  If you comment out the problem line, everything's peachy.  There's something about working with names while the chart sheet is active....  But there must be a way...

Dave
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dlmille

ASKER

Periods aren't the problem, and don't come into play with this particular error (at least at this exact moment, working with the chart sheet - but don't think it was a problem with the embedded charts that they support...)  

The code is actually failing on the testRangeSettings = Evaluate(rangeLabelSettings) , but perhaps with the refinement you suggest, it will succeed.

PS -  the assignment to the range, rangeLabelName works perfectly, but of course, that's a range, not a text string...  Why the scope is not needed with this but IS needed for the string, is puzzling still.

Dave
Avatar of dlmille

ASKER

What I'm trying to do is define range names that describe the chart affected, then return the Category/XValues range that's stored there.  That part works.  The enhancement I'm making is to store settings in a similar defined name (storing it works, but retrieving it is the problem) so that my chart wizardry can act on those stored settings...

My scheme was working, until this stumbling block.  I might be able to retrieve the scope of the labelrangesettings so I can build the range name via the chart's  category/XValues range so ----

anyway, I need to do that before I can test your proposed solution...

Dave
Avatar of dlmille

ASKER

We're golden. I fully qualified the defined name reference and then used evaluate like this:

    Set XValuesRange = getXValuesRange(activechart)
    rangeLabelName = "_" & Replace(activechart.Name, " ", ".") & "_RangeLabels"
    rangeLabelSettings = "'" & XValuesRange.Parent.Name & "'!_" & Replace(activechart.Name, " ", ".") & "_RangeLabels_Settings"

and the Evaluate(rangeLabelSettings) worked correctly.

Any consequences to this approach versus the Evaluate(sheet.names.item(name).value) approach you suggested?

Finally, I don't need to do Evaluate anymore.  With the fully-qualified name definition:

testRangeSettings = ActiveWorkbook.Names(rangeLabelSettings).RefersTo

works properly so I don't have to use Evaluate (which can cause problems - at least it created memory problems for me after calling it a few thousand times in a loop, recently, lol)

Dave
If it works then you're good. I don't see any issues at this point. I still don't like the periods in the name as they do cause problems but you are not concerned.

Kevin
Avatar of dlmille

ASKER

I'm indifferent and can make them underscores - will do to avoid the unanticipated.

Thanks,

Dave