Excel and Visual Basic

jwagus

New Member
Joined
Oct 17, 2002
Messages
4
I am using Visual Basic to manipulate Excel. In the code, I am trying to activate a chart.

The code is:

MyExcel.Application.ActiveWorkbook.ActiveSheet.ChartObjects("Chart 3").Activate

The error that I get in VB is:

Unable to get the ChartObjects property of the Worksheet class.

I am doing a loop to find the number value for the object (i.e., the 3), when I encounter an error, I increment a counter until I find the object. After finding the right one, I am presented with this error above.

Any ideas as to what I am doing wrong?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

rikrak

Active Member
Joined
Aug 21, 2002
Messages
255
Hi,

I don't like counting errors, but will this give you what you are after?<pre>
Sub getnum()
Dim chrt As ChartObject
For Each chrt In ActiveWorkbook.ActiveSheet.ChartObjects
If chrt.Name = "Chart 3" Then
num = chrt.Index
End If
Next
End Sub</pre>
This message was edited by rikrak on 2002-10-18 16:53
 

jwagus

New Member
Joined
Oct 17, 2002
Messages
4
I may not have been clear about my porblem.

My problem is not that I can't find the object (although that code is probably better than what I am using). The problem is that once I find it, I can't Activate the ChartObject.
 

rikrak

Active Member
Joined
Aug 21, 2002
Messages
255
I have no idea, but this works for me:
Excel.Application.ActiveWorkbook.ActiveSheet.ChartObjects("Chart 3").Activate

Maybe someone else around here has the answer.
 
L

Legacy 98055

Guest
Hi jw.
Please post the entire procedure. You may be creating an application object in a separate thread. This application object would have a separate collection of workbooks, sheets, ect...
Tom
 

Forum statistics

Threads
1,144,767
Messages
5,726,177
Members
422,660
Latest member
mrsteele

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top