ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   protect sheet macro problems (https://www.excelbanter.com/excel-discussion-misc-queries/144053-protect-sheet-macro-problems.html)

Nikki

protect sheet macro problems
 
Hi,

I have a macro that runs to insert rows when a button is clicked in my
sheet. This works fine when the sheet is unprotected but not when the sheet
is protected. Is there a way to protect certain cells in my sheet but have
it unprotected so my macro works?

Nikki

Gord Dibben

protect sheet macro problems
 
Nikki

If running Excel 2002 or higher you should be able to Protect the sheet with
Allow insert rows enabled under ToolsProtectionProtect sheet.

If running an earlier version you will have to Unprotect in code then do the
inserting then re-protect.

Sub yourmacro()
ActiveSheet.Unprotect Password:="justme"
'do the inserting code
ActiveSheet..Protect Password:="justme"
End Sub


Gord Dibben MS Excel MVP

On Thu, 24 May 2007 17:08:03 -0700, Nikki
wrote:

Hi,

I have a macro that runs to insert rows when a button is clicked in my
sheet. This works fine when the sheet is unprotected but not when the sheet
is protected. Is there a way to protect certain cells in my sheet but have
it unprotected so my macro works?

Nikki



ShaneDevenshire

protect sheet macro problems
 
Hi Nikki,

It is not necessary to unprotect and reprotect a sheet to allow the macro to
run against it, instead protect the sheet with the VBA below:

ActiveSheet.Protect Password:="mypass", UserInterfaceOnly:=True

From the help system: UserInterfaceOnly Optional Variant True to protect the
user interface, but not macros. If this argument is omitted, protection
applies both to macros and to the user interface.
--
Cheers,
Shane Devenshire


"Nikki" wrote:

Hi,

I have a macro that runs to insert rows when a button is clicked in my
sheet. This works fine when the sheet is unprotected but not when the sheet
is protected. Is there a way to protect certain cells in my sheet but have
it unprotected so my macro works?

Nikki



All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com