Protecting and locking all cells in all sheets

Discuss the spreadsheet application
Post Reply
jsquareg
Posts: 18
Joined: Wed Dec 03, 2014 7:01 pm

Protecting and locking all cells in all sheets

Post by jsquareg »

I am new to Open Office and to this forum so please forgive me if I violate some tenet of the group.

Under Excel, years ago, I constructed a macro in Personal.xls that would when invoked cycle through all sheets in a workbook and lock the cells in each sheet regardless of the number of sheets. It would also protect each sheet so that no cells could be changed without unlocking them. At the end of the macro it would then save that workbook.

I can't figure out how to do this under Oo's basic.

Will someone please help out here?

Thank you very much.
Open Office 4.1.1 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Protecting and locking all cells in all sheets

Post by Zizi64 »

Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Protecting and locking all cells in all sheets

Post by Zizi64 »

an example code:

Code: Select all

Sub ProtectAllSheets

Dim oDoc, oSheets, oSheet as object
Dim i as integer

oDoc = Thiscomponent
oSheets = oDoc.sheets
For i = 0 to oSheets.Count-1
oSheet = oSheets.getByIndex(i)
oSheet.Protect("")
Next i

End Sub
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
jsquareg
Posts: 18
Joined: Wed Dec 03, 2014 7:01 pm

Re: Protecting and locking all cells in all sheets

Post by jsquareg »

Thank you very much. That code cycles through each sheet nicely and protects each sheet as advertised. In addition to that, I need a statement or two to put in just before oSheet.Protect("") that will protect (lock) all the cells in the active sheet. Can you help there?

Thanks again.
Open Office 4.1.1 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Protecting and locking all cells in all sheets

Post by Zizi64 »

If the protection property of the cells was set in Cellstyles, then it is a simpliest case.
There is some example code in this topic for adjust cellstyles:
viewtopic.php?t=48960
You need adjust used cellstyles.

(The unused, empty cells - in a new Calc document - are set "protected" by default, you can activate this property by switching the "sheet protect" parameter.)


But, if the "Protect" property of the used cells was formatted and adjusted manually, that is athe hardest case. Then you must set cell by cell this parameter.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Protecting and locking all cells in all sheets

Post by Villeroy »

Make the file read-only.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply