-
Protect a Worksheet except while macro is running
Hi,
I would like to create a worksheet with some unlocked cells for the user to put inputs, and then launch a macro that writes the outputs in some other cells. I would like to lock the cells containing the outputs. How can I unprotect the sheet in my macro, and protect it again afterwards? Note that the user won't have the password to unlock the cells.
I hope I was clear enough.
Jungix
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
Jungix,
While you could protect the sheet on macro start and unprotect when it is complete, you could also just protect it setting the UserInterfactOnly argument to true. That keeps it unprotected for macros (while the workbook is open, it needs to be set again when closed/reopened) but protected to the user.
[vba]Sheets("Name").Protect Password:="abc",UserInterfaceOnly:=True[/vba]
Look in the VBA help at the protect method for more details.
Matt
-
.. but here's the unprotect version anyway!
[VBA]
ActiveSheet.Unprotect Password:="test"
ActiveCell.FormulaR1C1 = "Testing"
ActiveSheet.Protect Password:="test", DrawingObjects:=True, Contents:=True, Scenarios:=True
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Thanks!
I didn't think of putting the password in my code itself. What a dumb I am!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules