I am trying to write a macro that locks selected sheets of a spreadsheet, while allowing using filters in Libreoffice calc 25.2.
The version seems to be important here, as the macro I previously used does no longer work. (It does lock the sheets, but it does not allow using filters and pivot tables.
The no longer working macro is the following:
Code: Select all
Sub lock_sheets
Dim Doc As Variant
Doc = ThisComponent
Dim Sheet As Object
Dim sheet_to_lock as String
Dim sheets_to_lock(12) as string
sheets_to_lock(0) = "Sheet1"
sheets_to_lock(1) = "Sheet2"
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Protect"
args1(0).Value = true
For i = 0 to 12
If len(sheets_to_lock(i))>1 Then
Sheet = Doc.Sheets.getByName(sheets_to_lock(i))
dispatcher.executeDispatch("IKnowWhatIDo",document, ".uno:Protect", "", 0, args1())
REM Sheet.protect("IKnowWhatIDo")
End If
Next i
End Sub