Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with ChartObjects


Can somebody help me fix the following:

When I run the following line of code:

Worksheets(destinationSheet).ChartObjects(chartToC opy).Activate

where destinationSheet is a string with the name of the sheet "Output
2", and chartToCopy is also a string with the name of a chart "char 11"

I get a "Run-time error '1004':
Unable to get the ChartObjects property of the Worksheet class."


I think it worked when I used
Activesheet.ChartObjects(chartToCopy).Activate but I do not want to
make it dependent on being on that sheet.


--
pwermuth
------------------------------------------------------------------------
pwermuth's Profile: http://www.excelforum.com/member.php...o&userid=24997
View this thread: http://www.excelforum.com/showthread...hreadid=386289

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Problems with ChartObjects

"pwermuth" wrote in
message ...
When I run the following line of code:
Worksheets(destinationSheet).ChartObjects(chartToC opy).Activate
where destinationSheet is a string with the name of the sheet "Output
2", and chartToCopy is also a string with the name of a chart "char 11"
I get a "Run-time error '1004':
Unable to get the ChartObjects property of the Worksheet class."


My guess is you have an incorrect name in either your destinationSheet
or chartToCopy variable. Try hard-coding the names directly into the line of
code above and see if it works properly that way. If so, one variable or the
other has the wrong name in it (or if there are multiple worksheets with
chart objects on them you may have the name of a worksheet with the name of
a chart object that's located on a different worksheet).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Problems with ChartObjects

Your syntax is OK and it should work - it works for me running Excel 2002 on
Win XP. The most likely problem is that you do not have the correct names in
your variables (probably the chart name). I know you say the names are
correct but I don't see what else would be causing this to fail with the
error message you are getting. When you get the error go into debug mode and
check all the variables and the actual names, either through the locals
window or the immediate pane. And watch for extra spaces in any of the names
- that is often a problem that is hard to spot at first.

--
- K Dales


"pwermuth" wrote:


Can somebody help me fix the following:

When I run the following line of code:

Worksheets(destinationSheet).ChartObjects(chartToC opy).Activate

where destinationSheet is a string with the name of the sheet "Output
2", and chartToCopy is also a string with the name of a chart "char 11"

I get a "Run-time error '1004':
Unable to get the ChartObjects property of the Worksheet class."


I think it worked when I used
Activesheet.ChartObjects(chartToCopy).Activate but I do not want to
make it dependent on being on that sheet.


--
pwermuth
------------------------------------------------------------------------
pwermuth's Profile: http://www.excelforum.com/member.php...o&userid=24997
View this thread: http://www.excelforum.com/showthread...hreadid=386289


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Problems with ChartObjects

The only way I can replicate your problem is by spelling the name of the
chartobject wrong - i.e. if the ChartToCopy variable passes an incorrect
spelling you'll get this message. If the worksheet name is misspelled as
passed by the destinationSheet variable then I get the "subscript out of
range" message instead. Otherwise, your code works for me.

Regards,
Greg

"pwermuth" wrote:


Can somebody help me fix the following:

When I run the following line of code:

Worksheets(destinationSheet).ChartObjects(chartToC opy).Activate

where destinationSheet is a string with the name of the sheet "Output
2", and chartToCopy is also a string with the name of a chart "char 11"

I get a "Run-time error '1004':
Unable to get the ChartObjects property of the Worksheet class."


I think it worked when I used
Activesheet.ChartObjects(chartToCopy).Activate but I do not want to
make it dependent on being on that sheet.


--
pwermuth
------------------------------------------------------------------------
pwermuth's Profile: http://www.excelforum.com/member.php...o&userid=24997
View this thread: http://www.excelforum.com/showthread...hreadid=386289


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with ChartObjects


Thank you for your responses.

I will try hardcoding the name.

How can I check what the value of a variable is once I am in debug
mode? I am completely new to VB.


--
pwermuth
------------------------------------------------------------------------
pwermuth's Profile: http://www.excelforum.com/member.php...o&userid=24997
View this thread: http://www.excelforum.com/showthread...hreadid=386289



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Problems with ChartObjects

"pwermuth" wrote in
message ...
Thank you for your responses.
I will try hardcoding the name.
How can I check what the value of a variable is once I am in debug
mode? I am completely new to VB.


There are several ways to do this. For simple variables, once you are in
break mode all you should need to do is hover your mouse cursor over the
variable whose value you want to see and a yellow popup window will appear
that displays its current value.

The most robust way to see the value of a variable is to select it with
your mouse, right-click and choose Add Watch from the menu. Click OK in the
resulting Add Watch dialog and the Watch window will open with your variable
displayed in it, along with its value, data type and watch context.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Through Charts / ChartObjects William Benson[_2_] Excel Programming 2 June 29th 05 01:47 AM
delete chartobjects! Magnus Excel Programming 1 May 10th 05 01:01 PM
Not allow selection of chartobjects ? Gunnar Johansson Charts and Charting in Excel 0 May 8th 05 01:40 PM
Marcowarnings when pasting chartobjects to powerpoint Marie J-son Charts and Charting in Excel 2 March 3rd 05 02:54 AM
ChartObjects Nick Excel Programming 2 August 19th 04 12:04 PM


All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"