Solved

VBA Excel to set chart back ground to no fill

Posted on 2011-09-05
2
2,393 Views
Last Modified: 2012-06-21
Hi Experts

I have some code that sets the background of an active chart so that the gridlines can not be seen, code works fine, but the problem is that the background appears to be set by the shape control not the char control t, so if two charts are named the same then the back ground will only set on one chart, is there a better way to set the active shape as the current chart selected regardless of name?

ps. I know I can loop throught the number of shapes and set the shape based upon the chart name.

 
ActiveChart.PlotArea.Format.Fill.Visible = msoFalse
 ActiveSheet.Shapes(LTrim(Replace(ActiveChart.Name, ActiveSheet.Name, ""))).Fill.Visible = _
 msoFalse

Open in new window

0
Comment
Question by:MrDavidThorn
  • 2
2 Comments
 
LVL 80

Expert Comment

by:byundt
ID: 36484931
You might try looping through the ChartObjects collection to avoid conflicts with duplicate names. The code below sets the background color to white.

Sub ChartBackgrounds()
Dim co As ChartObject
For Each co In ActiveSheet.ChartObjects
    co.Chart.ChartArea.Format.Fill.ForeColor.RGB = RGB(255, 255, 255)
Next
End Sub

Open in new window

0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 36484935
This tweak to the original code sets the visibility of the Fill property to False for both the ChartArea and PlotArea.

Sub ChartBackgrounds()
Dim co As ChartObject
For Each co In ActiveSheet.ChartObjects
    co.Chart.ChartArea.Format.Fill.Visible = msoFalse
    co.Chart.PlotArea.Format.Fill.Visible = msoFalse
Next
End Sub

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now