I’ve been using IMPORTEXCEL in Powershell recently, to create Excel charts but I’m stuck on the syntax to change one bar chart column point colour. In VBA, I recorded a macro whilst carrying out the action and it created this:
ActiveSheet.ChartObjects(“Chart77DF”).Activate
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.FullSeriesCollection(1).Points(8).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
.Solid
End With
Application.CommandBars(“Format Object”).Visible = False
Below is an extract from my Powershell script that works. The last line changes the colour of the entire chart series to RED but I cannot work out how to emulate the VBA script to change just one column point of the bar chart. Any help would be much appreciated.
Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).
To change the colour of an individual datapoint you need to modify the XML that defines the chart.
The code below should be appended to your example script, hence I have not defined $chart in my code.
This will change the colour of the 5th datapoint (index 4) to green:
Many thanks Matt, I will give that a try and I take on board your point about preformatted text.
Just one question, I’ve seen code before that makes reference to http://schemas.openxmlformats.org but I’ve never fully understood what it is. Does this mean my script will always require internet access to run or is this looking something up under the hood of the chart?.
I ask because there may be times when it needs to be ran offline.