PC Review


Reply
Thread Tools Rate Thread

Dim cht as Object Constant Declaration

 
 
R Tanner
Guest
Posts: n/a
 
      24th Jun 2008
I have the simplest question ever. Why can I not declare this
variable? I think if you can give me a good answer you will solve my
confusion on declaring constants..

Dim cht As Object

cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart


Thanks and sorry I post so many questions...
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      24th Jun 2008
If you declare a variable as an object (including range or worksheet or workbook
or...), then you have to use the Set command:

Set cht = ....

R Tanner wrote:
>
> I have the simplest question ever. Why can I not declare this
> variable? I think if you can give me a good answer you will solve my
> confusion on declaring constants..
>
> Dim cht As Object
>
> cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart
>
> Thanks and sorry I post so many questions...


--

Dave Peterson
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      24th Jun 2008
It ius an object, so needs setting

Set cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"R Tanner" <(E-Mail Removed)> wrote in message
news:fec9f996-46c8-40b9-abb8-(E-Mail Removed)...
>I have the simplest question ever. Why can I not declare this
> variable? I think if you can give me a good answer you will solve my
> confusion on declaring constants..
>
> Dim cht As Object
>
> cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart
>
>
> Thanks and sorry I post so many questions...



 
Reply With Quote
 
RyanH
Guest
Posts: n/a
 
      24th Jun 2008
Your current code is using cht as a property of the "Chart 5". If you are
just wanting the Chart Property returned use this below.

Dim cht As Chart

cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart

If you want cht as a Chart Object then use this:

Dim cht As ChartObject

Set cht = Sheets("Cheet4").ChartObjects("Chart 5")

Ryan



"R Tanner" wrote:

> I have the simplest question ever. Why can I not declare this
> variable? I think if you can give me a good answer you will solve my
> confusion on declaring constants..
>
> Dim cht As Object
>
> cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart
>
>
> Thanks and sorry I post so many questions...
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      24th Jun 2008
The value of a Constant is defined when you write the code. You can't modify
the value of a constant at run time. Moreover, your code is missing the Set
statement which is required when you assign any sort of object to a
variable.

Dim CHT As Excel.Chart
Set CHT = Worksheets(1).ChartObjects(1).Chart ' Note 'Set' keyword
Debug.Print CHT.Name

Without the 'Set' keyword, VBA will attempt to find the Default property of
the Chart object, and I don't think there is a default property of a Chart
object.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





"R Tanner" <(E-Mail Removed)> wrote in message
news:fec9f996-46c8-40b9-abb8-(E-Mail Removed)...
>I have the simplest question ever. Why can I not declare this
> variable? I think if you can give me a good answer you will solve my
> confusion on declaring constants..
>
> Dim cht As Object
>
> cht = Sheets("Cheet4").ChartObjects("Chart 5").Chart
>
>
> Thanks and sorry I post so many questions...


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Codebehind and object declaration Andrew2 Microsoft ASP .NET 4 11th Sep 2007 09:04 AM
Object Declaration Dan, Wascus Microsoft Dot NET Framework Forms 0 18th Dec 2005 04:13 AM
Fancy Object Declaration rci Microsoft Excel Programming 1 3rd Feb 2004 10:13 PM
Database Object Declaration Michael R Microsoft Access Form Coding 4 23rd Oct 2003 09:42 PM
object array declaration, how ? andrewcw Microsoft C# .NET 1 20th Oct 2003 11:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:09 PM.