Well, I'm on 3.2.1. Hopefully the code here won't be affected.
I'm slightly confused by the VBA code though - it unprotects the ActiveSheet, then operates on one called "WI Personal Property Form," which implies to me that the latter is the same as the former. Perhaps I am missing something.
In any case, though ooBasic does have a For...Each these days, I do not see how it can be used in this case, because the Cells collection refers to all of the used cells on a sheet. This shouldn't be much of a problem though, just loop through all the cells in A7:E2000.
Code: Select all
Private Sub Auto_Close()
Dim ActiveWindow As Object
Dim ActiveSheet As Object
Dim WI_Personal_Property_Form As Object
Dim c As Object
Dim p As New com.sun.star.util.CellProtection
Dim col As Long
Dim row As Long
ActiveWindow = ThisComponent
ActiveSheet = ActiveWindow.CurrentController.ActiveSheet
ActiveSheet.unprotect("xxxxxx")
WI_Personal_Property_Form = ActiveWindow.Sheets.getByName("WI Personal Property Form").getCellRangeByName("A7:E2000")
For col = 0 to WI_Personal_Property_Form.Columns.Count - 1
For row = 0 to WI_Personal_Property_Form.Rows.Count - 1
c = WI_Personal_Property_Form.getCellByPosition(col,row)
p = c.CellProtection
If c.getType() = com.sun.star.table.CellContentType.EMPTY Then
p.IsLocked = False
Else
p.IsLocked = True
End If
c.CellProtection = p
Next row
Next col
ActiveSheet.protect("xxxxxx")
ActiveWindow.store()
ActiveWindow.Close(True)
End Sub
I don't think the Private on the Sub declaration is relevant here.