Solved

VBA Excel to set chart back ground to no fill

Posted on 2011-09-05
2
2,497 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 81

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 81

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

919 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

17 Experts available now in Live!

Get 1:1 Help Now