Can macros be used on protected sheets?

Discuss the spreadsheet application
Post Reply
Sophorus
Posts: 1
Joined: Fri Jan 25, 2008 8:18 pm

Can macros be used on protected sheets?

Post by Sophorus »

I have created a drill sheet for simple arithmetic operations. The sheet is intended to check the answers when a button is pushed (clicked) and to reset the entire sheet to a new set of problems when another button is pushed. To achieve this I inserted to buttons and linked each of them to a recorded macro. It worked fine, but only when the sheet is not protected. When I activate the sheet protection (to prevent accidental change to the formulas) a pop-up dialogue informs me that protected cells cannot be modified.

Is there a way I can reset the exercise (which means erasing the typed in answers, hide the check, and replace numbers with randomly generated new ones) using a button operated macro and have the macro operate on protected cells?

Thanks for any help,

Chris
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can macros be used on protected sheets?

Post by Villeroy »

This question belongs to http://user.services.openoffice.org/en/ ... m.php?f=20.

Code: Select all

oSh = thisComponent.Sheets.getByName("bla") 'by name
REM oSh = thisComponent.Sheets.getByIndex(0) ' sheet #1 by position
sPWD = "" 'password if any
oSh.unprotect("")
do_stuff
oSh.protect("")
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
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: Can macros be used on protected sheets?

Post by kingfisher »

Is it not possibly simply to unprotect the cells you wish to edit? Protection is at two levels. The first level is the cell level where the default style is set to cell protection. Protecting the sheet merely switches on the cell protection.

You have these options
# Use Menu: Format >Cells >Cell Protection to remove cell protection from certain cells
# Change the default style (F11) to remove cell protection from the default style and set protection for certain cells using the Format command
# Create a new style (F11) with or without cell protection depending on how you configure the Default style.
Apache OpenOffice 4.1.9 on Linux
Post Reply