excel vba problem

  • Thread starter Thread starter Patrick Elhorga
  • Start date Start date
P

Patrick Elhorga

Hi All,

I'm trying, using a VBA macro, to set the ChartArea.Height property of an Excel Graph object
but I'm getting the following error:

Run-time error '1004': Unable to set the Height of the ChartArea class

According to the MSDN documentation the Width is a read-write

My code is below. If anyone can shed some light on this it would be greatly appreciated.

I'm using Excel Small Business 2003

Regards,

Patrick

Sub Macro1()
''
Dim hauteur As Double
'
hauteur = 400#

ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Height = hauteur
End Sub
 
why not just set the height of the ChartObject

ActiveSheet.ChartObjects("Graphique 1").Height = hauteur + 5





--
Regards,
Tom Ogilvy

Hi All,

I'm trying, using a VBA macro, to set the ChartArea.Height property of an
Excel Graph object
but I'm getting the following error:

Run-time error '1004': Unable to set the Height of the ChartArea class

According to the MSDN documentation the Width is a read-write

My code is below. If anyone can shed some light on this it would be greatly
appreciated.

I'm using Excel Small Business 2003

Regards,

Patrick

Sub Macro1()
''
Dim hauteur As Double
'
hauteur = 400#

ActiveSheet.ChartObjects("Graphique 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Height = hauteur
End Sub
 
I use the following in my own chart formatting routine ...

------------------------------------------------------
'Place and Resize Chart Area
With ActiveSheet.ChartObjects(chtIndex)
.Activate
.Height = 250
.Width = 350
.Placement = xlFreeFloating
.PrintObject = True
.Locked = True
End With
------------------------------------------------

Note that the Height property is set using the ChartObjects object, not the
ChartArea object.

Regards,

Jim
 
Thanks a lot but this only works for chartobjects within a sheet

my problem concerns also charts within graph sheets where there is no
chartobjects
in this case it seems that I must use the "ActiveChart.ChartArea" object and
its height/width is not writable

--
Patrick. Elhorga ([email protected])
Project Manager
Geosciences Software Division
Beicip Franlab
tel: 33 (0)5 59 80 18 75
fax: 33 (0)5 59 84 42 96
___________________________________
Visit our Web site at http://www.beicip.com/
 
Hi, Patrick. I know this is years too late for your purposes, but I figured I would post the answer here for other poor souls who fall victim to the same Excel VBA design flaw which ensnared you.

To set the height of a chart, use:
ActiveChart.Parent.Height = hauteur
rather than:
ActiveChart.ChartArea.Height = hauteur
The same is true when setting the .Top, .Left, and .Width properties of a chart. Oh, and the .Name and .Index properties (used to specify a chart) should be accessed the same way (as, for example, ActiveChart.Parent.Name and ActiveChart.Parent.Index). The reference ActiveChart.Name does return a name, but VBA prepends the worksheet name to that name, so other functions won't recognize ActiveChart.Name as a valid chart name. :cry:

Seems like there might be other properties which need the Parent qualifier. New visitors, if you trip across another such property, please post information about it here.

For the record, I am running Microsoft Office Excel 2003 (11.8346.8341) SP3.
 
Back
Top