Libre office calc, used range

Hi,

I have a LibreOffice Calcs document, and with VBA, from a workshet, I would like to:
- Retrieve the used range of the worksheet.
- Iterate over cells in that used range.

Here is what I have done so far:
Dim openOffice As Object
Set openOffice = CreateObject("com.sun.star.ServiceManager")

Dim starDesktop As Object
Set starDesktop = openOffice.createInstance("com.sun.star.frame.Desktop")

Dim args(0) As Object
Set args(0) = openOffice.Bridge_Construct("com.sun.star.beans.PropertyValue")
args(0).name = "Hidden"
args(0).value = True

Dim doc As Object
Set doc = starDesktop.loadComponent.FromUrl("file://c:/temp/myDoc.ods", "_blank", 0, args)

Dim ws As Object
ws = doc.sheets().getByName("Sheet1")

    '// used range ??????????

Open in new window


NOTES:
The used range can be anywhere in the worksheet (doesn't necessary start with A1 cell).
LVL 15
Fabrice LambertConsultingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertConsultingAuthor Commented:
After many trials and errors, I found a solution:
Dim openOffice As Object
Set openOffice = CreateObject("com.sun.star.ServiceManager")

Dim starDesktop As Object
Set starDesktop = openOffice.createInstance("com.sun.star.frame.Desktop")

Dim args(0) As Object
Set args(0) = openOffice.Bridge_Construct("com.sun.star.beans.PropertyValue")
args(0).name = "Hidden"
args(0).value = True

Dim doc As Object
Set doc = starDesktop.loadComponent.FromUrl("file://c:/temp/myDoc.ods", "_blank", 0, args)

Dim ws As Object
ws = doc.sheets().getByName("Sheet1")

Dim cs As Object
Set cs = ws.createCursor
cs.gotoStartOfUsedArea False

Dim startColumn As Long
startColumn = cs.getRangeAddress().startColumn

Dim startRow As Long
startRow = cs.getRangeAddress().startRow

cs.gotoEndOfUsedArea False

Dim endColumn As Long
endColumn = cs.getRangeAddress().endColumn

Dim endRow As Long
endRow = cs.getRangeAddress().endRow

Dim rng As Object
Set rng = ws.getCellRangeByPosition(startColumn, startRow, endColumn, endRow)

Dim i As Long
Dim j As Long
For i = 0 To rng.rows.count - 1
    For j = 0 To rng.columns.count - 1
        Dim cell As Object
        Set cell = rng.getCellByPosition(j, i)
            '//
            '// code interracting with cell object
            '//
        Set cell = Nothing
    Next
Next

Set rng = Nothing
Set cs = Nothing
Set ws = Nothing
doc.close False
Set doc = Nothing
Set args(0) = Nothing
startDesktop.terminate
Set starDesktop = Nothing
Set OpenOffice = Nothing

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fabrice LambertConsultingAuthor Commented:
Solution found.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.