Ask Your Question
0

Protect sheet with password

asked 2017-03-11 10:08:16 +0100

msalsinha gravatar image

updated 2017-03-11 10:51:30 +0100

Lupp gravatar image

I need to block total access to a sheet.

Ex. Open calc document in sheet1 and if someone try to change to sheet2 block access with password.

Can someone help me?

Sorry for my poor English.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2017-03-11 10:57:46 +0100

Lupp gravatar image

updated 2017-03-11 12:31:41 +0100

You may protect any sheet using the submenu item 'Protect Sheet...' either using the context menu of its tab or via the main menu item 'Tools'.
Please note that the protection with a password done this way is weak. It can be removed from the file by means every interested user may know. It just is working in the opened document.

I want to expressly state that I don't know what the strange second submenu item 'Protect Spreadsheet...' under the main menu item 'Tools' should be good for.
I now would judge this is what formerly was labeled more clearly 'Protect Document', and should even better be called 'Protect Sheet Properties'. (See also my comment below.)

edit flag offensive delete link more

Comments

Thanks for your answer, but what a pretend is avoid open that sheet, not only protect sheet edition! Or in last resource, block edition for forms control like combo box or list box.

msalsinha gravatar imagemsalsinha ( 2017-03-11 12:04:16 +0100 )edit

From the OQ: "Open document in sheet1 and if someone try to change to sheet2 block access with password." Here the 'Protect Spreadsheet...' option comes in. If you hide a sheet and after that activate that option (using a passwiord) the sheet cannot be shown again, and thus also not entered.

Since this may be a sensitive subject concerning security I would like to state that I still don't feel sure to understand the question correctly.

Anyway this kind of protection is weak.

Lupp gravatar imageLupp ( 2017-03-11 12:29:47 +0100 )edit

Unfortunately that solution don't work for me. I need sheet2 stay visible, but if someone click on it appears some type of block, preferred lock access and only unlock only by introduce password.

msalsinha gravatar imagemsalsinha ( 2017-03-12 00:35:36 +0100 )edit

I meanwhile ceased to believe I understood what you want to achieve. Please explain what you actually want to protect/hide and for what reason. There might be better ways than those you are thinking of.
"Total access" will be blocked by default for protected sheets. What kinds of access, precisely, do you want to block?

Lupp gravatar imageLupp ( 2017-03-12 11:57:14 +0100 )edit

I intent to create a document with two sheet that ill be used by many people. In sheet1 I want insert some kind of form to people fill in and in sheet2 I want to insert some configuration commands(combo box and list box whit macro association), this commands I want restrict access only to people that know what are doing, without destroying anything important. I don't need high security level, because a don't need to hide nothing I only want avoid document destruction.

msalsinha gravatar imagemsalsinha ( 2017-03-12 19:52:15 +0100 )edit

If you protect a sheet the cells are protected on the level you chose under 'Format Cells...' > 'Cell Protection'. In addition you can prevent the selection of protected cells or of all the cells of the sheet when switching on the sheet protection. Form controls will also be protected against editing but not against being used. If you want to disallow usage of controls you have to hide or to disable them.

Lupp gravatar imageLupp ( 2017-03-12 22:20:15 +0100 )edit
0

answered 2017-03-14 00:23:09 +0100

msalsinha gravatar image

I find something very close to what I want. I already edit something but I'm block e two situations: in password verification and send back to sheet1 if password is wrong.



sub PASSWORD

  ' Criar o diálogo
  oDialog = CreateUnoService("com.sun.star.awt.UnoControlDialog")
  oDialogModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
  oDialogModel.setPropertyValues( _
    Array("Height","PositionX","PositionY","Title","Width"), _
    Array(50,200,150,"Insira a sua senha",100))
  oDialog.setModel(oDialogModel)

  ' Criar a caixa de texto (oEditModel) que receberá a senha.
  oEditModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlEditModel")
  oEditModel.setPropertyValues( _
    Array("EchoChar","Height","PositionX","PositionY","Width"), _
    Array(asc("*"),15,5,5,90) )
  oEditModel.EchoChar = asc("*")
  oDialogModel.insertByName("PasswordEdit",oEditModel)

  ' Criar o botão "Cancelar" e o botão "Ok"
  oOKButton = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
  oOKButton.setPropertyValues( _
    Array("DefaultButton","Height","Label","PositionX","PositionY","PushButtonType","Width"), _
    Array(True,15,"~OK",55,25,1,40))
  oDialogModel.insertByName("OkButton",oOKButton)
  oCancelButton = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
  oCancelButton.setPropertyValues( _
    Array("Height","Label","PositionX","PositionY","PushButtonType","Width"), _
    Array(15,"~Cancelar",5,25,2,40))
  oDialogModel.insertByName("CancelButton",oCancelButton)

  oSheet = ThisComponent.Sheets.getByName("sheet1")


  oDialog.setVisible(True)
  If oDialog.execute() = 1 Then AND 'I can't make password verification in here'

  MsgBox "PASSWORD ACCEPT",48,"ATENTION!"

else

  MsgBox "INVALID PASSWORD",48,"ATENTION!"

GoTo

  oSheet  'In here a need to send back to sheet1 if password is invalid'

End If

End Sub

edit flag offensive delete link more

Comments

@msalsinha:
Would you mind to show me to the statement(s) in the above code actually changing the state of protection?
Would you mind to tell me how you understood the line
If oDialog.execute() = 1 Then AND 'I can't make password verification in here'

In my opnion you only have a completely superfluous dialog without any relevant functionality. By what are you committed to complicated solutions instead of using simple ones? Calc sheets come with a password dialog!

Lupp gravatar imageLupp ( 2017-03-14 10:43:20 +0100 )edit

What do you expect to achieve by obscure "macros" what you don't get by the standard means I pointed you to?

Lupp gravatar imageLupp ( 2017-03-14 10:49:20 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-11 10:08:16 +0100

Seen: 568 times

Last updated: Mar 14 '17