How can I execute macro when the sheet is protected? Unprotected the sheet and protect it after, I believe.
Here is what I needed, but I will call them from another sub, unprotect → write → protect.
I hope it can help someone else.
'-----------------------------------------------Annuler la Protection de la feuille-------------------------------------
sub Unprotect_Sheet
rem ----------------------------------------------------------------------
rem define variables
dim oSheets as object
dim doc as object
dim mysheet as object
rem ----------------------------------------------------------------------
doc = ThisComponent
mysheet = doc.CurrentController.ActiveSheet
oSheets = doc.Sheets.getByName(mysheet.name)
oSheets.unprotect("password")
end sub
'-----------------------------------------------Protéger la feuille-------------------------------------
sub Protect_Sheet
rem define variables
dim oSheets as object
dim doc as object
dim mysheet as object
doc = ThisComponent
mysheet = doc.CurrentController.ActiveSheet
oSheets = doc.Sheets.getByName(mysheet.name)
oSheets.protect("password")
end sub
'-------------------------------------------------Fin De La Protection de la feuille---------------------------------------------
1 Like
>Sub SheetProtection ( oSheet$, oSenha$, onoff$ )
Select Case onoff
Case "on" : ThisComponent.Sheets.getByName( oSheet ).Protect( oSenha )
Case "off" : ThisComponent.Sheets.getByName( oSheet ).Unprotect( oSenha )
Case Else : MsgBox "Error", 0, "SheetProtection"
End select
End Sub
>Sub ActiveSheetProtection ( oSenha$, onoff$ )
Select Case onoff
Case "on" : ThisComponent.getCurrentController.getActiveSheet().Protect( oSenha )
Case "off" : ThisComponent.getCurrentController.getActiveSheet().Unprotect( oSenha )
Case Else : MsgBox "Error", 0, "ActiveSheetProtection"
End select
End Sub