I have some VBA code that runs a SQL Query, dumps it into an Excel 2010 spreadsheet and refreshes the 2 Pivot Tables based off the data. I also have 2 Pivot Charts based off of the Pivot Tables, and every time the Tables get updated, the formatting on the Charts is lost.
I followed the instructions in Section 12.3 of this book which suggested creating a custom chart type based on my formatting preferences and applying it to the charts that I want to have remain formatted that way. These instructions work great if I manually modify the data then manually refresh the Pivot Table - the Charts remain properly formatted. However, when I execute this code:
For Each pt In NewSheet.PivotTables
pt.RefreshTable
Next
the formatting is immediately lost.
Here's what the data looks like before:
and my carefully crafted pie charts:
As soon as I update the data and refresh the tables:
This is what I get:
Again, having the custom chart style applied will keep the formatting if done manually, but executing the VBA code somehow resets the custom chart type.