The best I could do for this was to modify a recorded macro as follows:
Code: Select all
REM SetProtectionOn()
Sub SetProtectionOn()
'Purpose: Wrapper for SetProtection. Turn protection on.
SetProtection( True )
End Sub
REM SetProtectionOff()
Sub SetProtectionOff()
'Purpose: Wrapper for SetProtection. Turn protection off.
SetProtection( False )
End Sub
REM SetProtection(a)
REM a is true or false, a boolean, optional
Sub SetProtection( Optional switch As Boolean )
'Purpose: To protect a spreadsheet. This is developed from a macro
'recording. Invokes the standard protect/unprotect dialog. Set pro-
'tection on by default.
On Error GoTo ErrorHandler
'Declare
Dim _document As Object
Dim _dispatcher As Object
Dim _switch As Boolean
Dim _args(0) As New com.sun.star.beans.PropertyValue
'Initialize
_document = ThisComponent.CurrentController.Frame
_dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
_switch = True 'On by default.
If Not isMissing( switch ) Then
_switch = switch
End If
_args(0).Name = "Protect"
_args(0).Value = _switch 'True or False
_dispatcher.executeDispatch( _document,".uno:Protect","",0,_args() )
Exit Sub
ErrorHandler:
'This traps errors that might occur when, for example, protection is already
'on when SetProtection(True) is invoked. So we simply stop execution to avoid
'risk of undefined behaviour.
Stop
End Sub
So I was wondering if there are any secrets of the temple that might offer a way to achieve the same within a macro, without having to deal with any dialog interaction ...