Set spreadsheet row height to optimal value from macro

I have a spreadsheet document with n sheets. The sheets contain 0-x annotations.

I have a macro which walks through all sheets and creates one sheet for comments per sheet (i.e. if there is 20 sheets with annotations, then there will be 20 sheets which list the annotations.) The annotations are listed in one column rows.

Because the annotations vary in lengths, I want to be able to automatically set the height of rows according to the text line(s). I.e. I want to say to all cells (as I have only one column) to be of certain width and then call subroutine “SetOptimalRowHeight” to the rows. As a result, all text is visible.

Manually I do this by selecting all rows and invoking the “Optimal Row Height” property. But how to do this from my macro?

I found some examples, but unfortunately I couldn’t get them to work. e.g [Solved] Row height buggy when done by macro (View topic) • Apache OpenOffice Community Forum

The part of macro where I would like to set the optimal width

oRows = oSheet2.getRows()
For k = oRows.getCount()-1 To 0 Step k-1
    oRow = oRows.getByIndex(k)
    'oRow.OptimalHeight = TRUE  
    'Call SetRowToOptimalHeight(oRow,oSheet2)