Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveSheet.Name not working when used with ActiveChart.Location? 1

Status
Not open for further replies.

KiwiSteve

Programmer
Joined
Feb 5, 2005
Messages
2
Location
GB
I have a macro which constructs a chart - it works fine with hard-coded sheet names, but I need it to work on other sheets. When I substitute the sheet name with ActiveSheet.Name it no longer works...

eg. This works:

ActiveChart.Location Where:=xlLocationAsObject, _
Name:= "JAN05 (01FEB05 @ 1524)"

This doesn't:

ActiveChart.Location Where:=xlLocationAsObject, _
Name:=ActiveSheet.Name

Any help would be greatly appreciated. I've been stuck on this now for 2 days!

Regards,
Steve
 


Hi,

Problem is, the active THING is NOT a sheet; rather its a CHART.

if you go to the VB Editor and STEP thru the code, you'll see that your new chart is originally a Chart Sheet and NOT an embedded chart in a worksheet.


Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Thanks for the tip!

Setting up the sheet name outside the "charting block"...

Dim SheetName As String
SheetName = ActiveSheet.Name

...followed by...

ActiveChart.Location _
Where:=xlLocationAsObject, _
Name:=SheetName


Did the trick nicely.
 


I would get in the habit of NOT relying on SELECT and ACTIVATE, referring to ActiveWhatever. Rather refer to SPECIFIC objects. Selecting and Activating slows down your program and can be confusing.

How Can I Make My Code Run Faster? faq707-4105

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top