Solved

VBA Excel to set chart back ground to no fill

Posted on 2011-09-05
2
2,888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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