KahEm Chu
Feb 11, 2023

--

Hi Dongduke,

Thank you for your question, I do learn a lot by trying to find the solution.

Yeah, I think pywin32 doesn't have a constant name msoElementChartTitleAboveChart, but then I found out there are actually number code for this constant, where I tested it out and it works 🎉. For your case, the number code will be 2, you may refer more here, https://learn.microsoft.com/en-us/office/vba/api/office.msochartelementtype

--------------

The code will be as below.

pvtTable = wb.Sheets("pivot_table").Range("A3").PivotTable

chart = wb.Sheets("pivot_table").Shapes.AddChart2()

chart.Chart.SetSourceData(Source= pvtTable.TableRange1)

chart.Chart.SetElement(2)

--

--

KahEm Chu
KahEm Chu

Written by KahEm Chu

Date Science and Analytics Graduate. Passionate in data science, decision science and automating stuff =]

Responses (1)