background-foreground color

  • Thread starter Cenk Ursavas via OfficeKB.com
  • Start date
C

Cenk Ursavas via OfficeKB.com

HOw can I change the background and foreground color of an excel graph?
I tried :
------------------------------------
With myChart.ChartArea.Fill
.Visible = True
.ForeColor.SchemeColor = 15
.BackColor.SchemeColor = 17
End With
 
G

Guest

If you are working with an embedded chart, select the outside of the chart
and run this macro:

Sub ChangeColors1()
ActiveChart.ChartArea.Interior.ColorIndex = 8
ActiveChart.PlotArea.Interior.ColorIndex = 7
End Sub

To change the ChartArea and PlotArea colors for all embedded charts on the
worksheet, you can use something like this:

Sub ChangeColors2()
Dim ChtObj As ChartObject
For Each ChtObj In ActiveSheet.ChartObjects
ChtObj.Interior.ColorIndex = 4
ChtObj.Chart.PlotArea.Interior.ColorIndex = 3
Next ChtObj
End Sub

If you're using a chart sheet, try:

Sub ChangeColors3()
Dim Cht As Chart
Set Cht = Sheets("Chart2")
Cht.ChartArea.Interior.ColorIndex = 8
Cht.PlotArea.Interior.ColorIndex = 7
End Sub
 
G

Guest

I have a similar dilemma, but have yet to figure-out the solution.

Sheet 1, cell A1 contains +1, 0 or -1 (derived from contents of another
workbook).
Sheet 2 contains an imbedded line chart.

How does one dynamically code for the 'chart area', (leaving the 'plot area'
as-is), of the chart in sheet 2 to be:
a) green if Sheet1,A1 is +1
b) grey if Sheet 1, A1 is 0
c) red if Sheet 1, A1 is -1

???
 
G

Guest

Borrowed and adapted from Jim Cone's example in Subject: Re: help new to vba
- charts?? 2/27/2005 4:50 PM PST By: Jim Cone In:
microsoft.public.excel.programming

You can quickly see examples of the chartarea colors available to you by
doing the following:

1. From your sheet that contains a chart, select "Restore Down" (upper-right
on the display-screen, middle box). This displays a smaller, but adequate,
view of your chart.

2. From the display that results from step 1, open the Visual Basic Editor
under Tools, Macro, Visual Basic Editor. Or, select Alt+F11. Either should
result in the same display of the Visual Basic Editor.

3. Copy this code into the Visual Basic Editor:

Sub ColorTest()
Dim chtRate As Excel.Chart
Dim lngColor As Long
'Make an object reference to the chart within the ChartObject
Set chtRate = ActiveSheet.ChartObjects(1).Chart
'What is the current color?
lngColor = chtRate.ChartArea.Interior.ColorIndex
'Good, now make the next color
lngColor = lngColor + 1
'Show the next chartarea color
chtRate.ChartArea.Interior.ColorIndex = lngColor
Set chtRate = Nothing
End Sub

4. On the bottom of your PC display, left-click the Microsoft Excel button.
This should result in your screen showing two Window items:
a) Your chart and b) the Visual Basic Editor.

5. At the top of your Visual Basic Editor window, there's an arrow pointing
right (just under the word "Debug"). When you point your mouse at it, a
"popup text" says "Run Sub/UserForm". Left-click that arrow.

6. Every time you left-click the "Run Sub/UserForm" arrow, you should see
your chart's chartarea change color. This will show you several-dozen colors
that you can use for your chartarea.

If you haven't decided what looks best, keep clicking :) You will continue
to see different colors until you do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top