Macro to change All Chart Backgrounds to white

GorD

Well-known Member
Joined
Jan 17, 2004
Messages
1,447
My boss as a pet hate for charts that have the standard grey background (as it wastes too much ink when printing). Does anyone have a macro to change the background colour of all charts in a workbook to white

Thanks a lot
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
the code to change from grey to white is:

Code:
    With Selection.Border
        .ColorIndex = 16
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    With Selection.Interior
        .ColorIndex = 2
        .PatternColorIndex = 1
        .Pattern = xlSolid
    End With

You will need to use:

Code:
for a = 1 to n

next a

to cycle through the graphs, this code will depend on where the graph is ie:new sheet or on the page.
 
Upvote 0
I would like it to cover all graphs whether on a separate sheet or part of an existing sheet.

Is that possible?
 
Upvote 0
okay, first you need to know how many workbooks there are:

Code:
a = Activeworkbook.sheets.count

For b = 1 to a

    sheets(b).activate

    'then you need find the number of graphs
    d = ActiveSheet.ChartObjects.Count

    For c = 1 To d

        ActiveSheet.ChartObjects(c).Activate
        ActiveChart.ChartArea.Select
 
        'INSERT THE CODE FOR COLOUR CHANGE HERE

    Next c

next b

Bobs your uncle, your done. (I think)
 
Upvote 0
You could speed it up a bit if you have lots of sheets by adding an if statement.

if d<>0 then



end if

next b
 
Upvote 0
Thanks a lot I'll give it a go

Just to clarify I only need one workbook but to cover all charts but that should do nicely

Thanks again
 
Upvote 0
I have another suggestion which may or may not be helpful- if you are the one generating the charts, you can set up a custom chart type in excel and set that as the default chart type- then, whenever you generate a chart, the background will always be white.
 
Upvote 0
In trying to follow Aussie Robs suggestion I came up with this:

Code:
Sub GraphBGroundToWhite()
'
' GraphBGroundToWhite Macro
' Macro recorded 01/02/2005 by G Dickson
'
a = ActiveWorkbook.Sheets.Count

For b = 1 To a

    Sheets(b).Activate

    'then you need find the number of graphs
    d = ActiveSheet.ChartObjects.Count

    For c = 1 To d

        ActiveSheet.ChartObjects(c).Activate
        ActiveChart.ChartArea.Select

        With Selection.Border
        .ColorIndex = 16
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    With Selection.Interior
        .ColorIndex = 2
        .PatternColorIndex = 1
        .Pattern = xlSolid
    End With

    Next c

Next b
'
End Sub
[code]
Unfortunately, It dosen't change the background colour of the charts. Have I got it wrong? 

Any suggestions?
 
Upvote 0
Hi GorD

Try this

Sub ChartBackgrounds()
Dim cht As ChartObject
Dim sht As Worksheet
Dim chart As chart

For Each sht In ThisWorkbook.Worksheets
For Each chart In ThisWorkbook.Charts
For Each cht In sht.ChartObjects
chart.PlotArea.Interior.ColorIndex = xlNone
cht.chart.PlotArea.Interior.ColorIndex = xlNone
Next cht
Next chart
Next sht
End Sub


HTH

Regards
 
Upvote 0

Forum statistics

Threads
1,203,047
Messages
6,053,195
Members
444,645
Latest member
mee siam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top