Automate chart titles with macros
From
stackoverflow
i have this code. I want to loop through all chart, and give main title to charts from specific cells.
e.g. A1, b3, c4, z2, x7.
How can i change that code in order to do that?
( I did some changes )
Const SColumns = “L8, T8, AA8”
’ Set the title of the first Chart to the contents of C1
Sub SetTitle
’ Get active sheet
oSheet = ThisComponent.CurrentController.ActiveSheet
aColumns = Split(SColumns,",")
for i = uBound(aColumns) to 0 step 3
' Get the cell containing the chart title, in this case C1
oCell = oSheet.getCellRangeByNamee(aColumns(i))
oCharts = oSheet.getCharts()
' Get the chart with index 0, which is the first chart created
' to get the second you would use 1, the third 2 and so on...
oChart = oCharts.getByIndex(i)
oChartDoc = oChart.getEmbeddedObject()
'Change title
oChartDoc.getTitle().String = oCell.getString()
next i
End Sub
Sincerely,
Elias Tsolis
Statistician