I'm having difficulties with a macro Chart.getRanges call in that sometimes it
doesn't return a list of chart data ranges that I know for sure are there.
Typically when it does work I get a 2 element array, when it doesn't work I
get an empty array.
Is there something wrong with the example code below?
Is there a better more reliable way to get chart data ranges
Craig Johnson
-------------
Type myCellAddressType
Column as String
Row as Long
End Type
Sub Example
Dim myEndCellAddress as myCellAddressType
myEndCellAddress.Row = 100 ' example value
Dim Sheets as Object
Dim Sheet as Object
Dim Charts as Object
Dim Chart as Object
Dim ChartRanges() as Object
Sheets = ThisComponent.getSheets()
Sheet = Sheets.getbyname("mySheet")
ThisComponent.CurrentController.setActiveSheet(Sheet)
Charts = Sheet.getCharts()
' Assume there is only one chart per sheet
Chart = Charts.getByIndex(0)
ChartRanges = Chart.getRanges()
MsgBox("count=" & count & " : UBound(ChartRanges)=" & UBound(ChartRanges()))
Dim s as String
Dim sCell as Object
Dim eCell as Object
Dim i as Integer
s = "Chart range is" & Chr$(13)
For i = LBound(ChartRanges()) To UBound(ChartRanges())
sCell =
Sheet.getCellByPosition(ChartRanges(i).StartColumn,ChartRanges(i).StartRow)
eCell =
Sheet.getCellByPosition(ChartRanges(i).EndColumn,ChartRanges(i).EndRow)
s = s & PrintableAddressOfCell(scell) & ":" &
PrintableAddressOfCell(ecell)
' Change end row of range to new value.
' Must subtract 1 from new end cell address row
ChartRanges(i).EndRow = myEndCellAddress.Row-1
ecell =
Sheet.getCellByPosition(ChartRanges(i).EndColumn,ChartRanges(i).EndRow)
s = s & " :: New end cell is " & PrintableAddressOfCell(ecell) &
Chr$(13)
Next i
MsgBox(s)
Chart.setRanges(ChartRanges())
End Sub
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]