PDA

View Full Version : Chart's size and border color?



oleval
01-24-2008, 05:31 AM
Hi All! I need your help to solve two problems:

1. I'd like to have VBA code on setting the width and height of the selected chart. I tried to use the following code, but it caused an error 'Unable to set the Width property of the ChartArea class'. I can't figure out what is wrong with this, should I try other properties?
...
.ChartArea.Width = 200
.ChartArea.Height = 100
...

2. Another problem is with chart's border color. I tried this code
.ChartArea.Border.ColorIndex = RGB(255, 255, 255)

but it appeared it was a wrong way. I'd like to set the border as a transparent one.

Thank you very much in advance!

Bob Phillips
01-24-2008, 06:37 AM
With ActiveSheet.ChartObjects(1)

.Width = 200
.Height = 100
.Border.LineStyle = xlNone
End With

oleval
01-24-2008, 06:46 AM
This does not work in the following code :((( I use the sub that looks like this

Dim objChart As Chart
Set objChart = ActiveChart
With objChart
.Width = 200
.Height = 100
End with

Some other advice?

This code is very helpful, thank you!
Border.LineStyle = xlNone

Bob Phillips
01-24-2008, 07:03 AM
Dim objChart As Chart
Set objChart = ActiveChart
With objChart.Parent
.Width = 200
.Height = 100
.Border.LineStyle = xlNone
End With

oleval
01-24-2008, 07:09 AM
Thank you!!!

One additional question: how correcly assign color to the chart. I tried both options in the above mentioned code and all the time it was run-time error
.ChartArea.Border.ColorIndex = 37
.ChartArea.Border.ColorIndex = RGB(255, 255, 255)

Bob Phillips
01-24-2008, 07:42 AM
Dim objChart As Chart
Set objChart = ActiveChart
With objChart.ChartArea
With .Border
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 3
End With
End With

oleval
01-24-2008, 07:54 AM
Thank you!

Actually, I'd like to fill the chart area with certain color. I tried this code and found it is wrong. Can you advice me on this?


With .ChartArea.Fill
.ColorIndex = 3
End With

Bob Phillips
01-24-2008, 09:12 AM
Dim objChart As Chart
Set objChart = ActiveChart
With objChart.ChartArea
.Interior.ColorIndex = 40
With .Border
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 3
End With
End With

oleval
01-24-2008, 10:06 AM
Thank you so much!