vbalibreofficelibreoffice-calcopenoffice-basiclibreoffice-basic

ActiveCell.Offset for libreoffice


How can I get access to nearby of selected cell in LibreOffice (OpenOffice)?

I can get only selected cell with "ThisComponent.getCurrentSelection".

I just need an alternative for MS Excel VBA function "ActiveCell.Offset".


Solution

  • It seems pretty simple to me:

    Function OffsetCell(col_offset, row_offset)
        oSel = ThisComponent.getCurrentSelection()
        oCellAddress = oSel.getCellByPosition(0, 0).getCellAddress()
        oSheet = ThisComponent.CurrentController.ActiveSheet()
        OffsetCell = oSheet.getCellByPosition( _
            oCellAddress.Column + col_offset, _
            oCellAddress.Row + row_offset)
    End Function
    

    For example, the function could be used like this:

    Sub DisplayOffsetCell()
        offset_cell = OffsetCell(2, 1)
        MsgBox(offset_cell.getString())
    End Sub
    

    For reasons I do not understand, there has been quite a bit of discussion about this topic, and several complex solutions have been proposed: