Search code examples
openoffice.orgopenoffice-calcuno

OpenOffice Basic Select All


Does anyone know how to select all the used cells in an OpenOffice Basic Macro? I found this other question telling how to do it with pyUno:

OpenOffice pyuno "select all"

I tried just writing the same code in Basic, but I get an error on the last line:

sheet = ThisComponent.getSheets().getByName(sheetName)
range = sheet.getCellRangeByPosition(0, 0, 0, 0)
range.gotoEndOfUsedArea(True)

The error is Property or method not found, so I guess that means the python method gotoEndOfUsedArea doesn't exist for Basic. Perhaps it is wrapping some other call I can make?

I'm on OpenOffice 3.1.1.


Solution

  • The gotoEndOfUsedArea() belongs to a cursor-object, rather than to a range-object. So you have to do the Basic equivalent to

    sheet = ThisComponent.getSheets().getByName(sheetName)
    cursor = sheet.createCursor()
    cursor.gotoEndOfUsedArea(True)
    address = cursor.RangeAddress
    endcol = address.EndColumn
    endrow = address.EndRow
    range = sheet.getCellRangeByPosition(0, 0, endcol, endrow)
    

    I am not familiar with Basic and OpenOffice and so can not provide a solution in Basic, but I hope this python answer does still help.