Search code examples
excelopenoffice-calcopenoffice-basicvba

Get the formatted text of a range/cell object


I try to concatenate the formatted contents of some cells with a formula.
As I cannot see a way to solve it with a pure formula I add some basic code.

But I cannot figure out how to access the formatted text value out of the single cells.
It seems that oCell isn't a cell object, instead it is only the cell content.

How do I could change this, so I can use something like oCell.Text or oCell.String ...

Function StringSumme(oCellRange )
    dim result as String
    dim nRow as Integer

    result = ""
   For nRow = LBound( oCellRange, 1) To UBound( oCellRange, 1 )
        For nCol = LBound( oCellRange, 2) To UBound( oCellRange, 2 )
            oCell=oCellRange(nRow,1)
            result = result + oCell
        Next 
    Next 
    StringSumme = result 
End Function

In Excel this one works

Function StringSumme(bezug As Range) As String
    Dim txt As String
    Dim ce As Range

    txt = ""
    For Each ce In bezug.Cells
        txt = txt & ce.Text
    Next
    StringSumme = txt
End Function

Solution

  • jeb

    I think I understand your question now.

    When you type this

    Function StringSumme(oCellRange)
    

    oCellRange is not a range. It is an array which is being passed. And hence oCell isn't a cell object, instead it is only the cell content as you right guessed.

    You might want to change it to something like

    oCell = Sheet.getCellByPosition(X, Y)

    and then use oCell.Value

    Interesting Read

    http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Cells_and_Ranges