Lock cell with macro
Hello! I would like to lock a cell in order to prevent that the user could write in, I use the command oCell.cellprotection.isLocked = True/False but don't run,
Can You help me?
Thank you
Have a nice day
P.S. I tried to use the command:
cp = createUnoStruct("com.sun.star.sheet.CellProtection")
Dim cp as new com.sun.star.sheet.CellProtection
but nothing happens
News: I don't understand whi this code don't run :/
Sub test(pPass$, kj#)
oSheet = ThisComponent.getSheets().getbyname("Prova")
oSheet.UnProtect(pPass)
oCellRange = oSheet.GetcellRangebyname("Data")
oCell = oCellRange.getCellByPosition(2,6)
select case kj
case 1
oCell.cellbackcolor = RGB(255,255,0)
hh = oCell.CellProtection
hh.IsLocked = False
oCell.CellProtection = hh
case 2
oCell.clearContents(1)
oCell.cellbackcolor = RGB(255,255,255)
hh = oCell.CellProtection
hh.IsLocked = True
oCell.CellProtection = hh
end select
oSheet.Protect(pPass)
End Sub
Concerning the "News".
(Suggestion: Format code more compact for better overview.)
How did you pass the parameter values to the
Sub
?Did you run the code step by step in the debugger? Your observations?
What's your LibO version? Your OS and its version?
Attach "the real thing": the .ods file (after removing confidential content where applicable).