I have tried the Sub shown below and when run as a macro, I get a message saying something like 'Incorrect number of parameters.' I suspect it is because oRange has not been set anywhere and I haven't a clue how go go about setting it. I am very new to Oo's Basic. I want to lock ALL the cells in the active sheet. The workbook is an Excel (xlm) converted to an ods book and I know nothing about using Styles. Would you be kind enough to tell me how to to go about setting oRange to all the cells in a sheet?
Code: Select all
Sub LockCells(oRange As Object)
rem ----------------------------------------------------------------------
Dim Doc As Object
Dim oSheet As Object
Dim oCell As Object
Dim p As New com.sun.star.util.CellProtection
Dim col As Long
Dim row As Long
Doc = ThisComponent
oSheet = Doc.Sheets(oRange.RangeAddress.Sheet)
oSheet.unprotect("")
For col = 0 to oRange.Columns.Count - 1
For row = 0 to oRange.Rows.Count - 1
oCell = oRange.getCellByPosition(col,row)
p = oCell.CellProtection
If oCell.getType() <> com.sun.star.table.CellContentType.EMPTY and not p.IsLocked Then
p.Islocked = True
oCell.CellProtection = p
End If
Next Row
Next col
oSheet.protect("")
End Sub