Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Dim cht as Object Constant Declaration

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...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Dim cht as Object Constant Declaration

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Dim cht as Object Constant Declaration

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" wrote in message
...
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...



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Dim cht as Object Constant Declaration

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...

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Dim cht as Object Constant Declaration

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" wrote in message
...
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
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
if declaration ashw1984 Excel Programming 2 January 30th 06 07:35 PM
Declaration name Robert Hargreaves[_2_] Excel Programming 4 June 6th 05 04:48 PM
which declaration to use Peer Excel Programming 3 August 2nd 04 03:17 PM
Fancy Object Declaration rci Excel Programming 1 February 3rd 04 10:13 PM
Declaration? TJF[_2_] Excel Programming 5 December 18th 03 03:26 PM


All times are GMT +1. The time now is 08:11 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"