hello, can we run a macro on proteicted sheet if so how ? thanks in advance.
D Dave Peterson Jan 4, 2007 #2 Sure. But some of the features you try to use may not be available on a protected worksheet. A typical solution is to unprotect the worksheet, run the real code and the reprotect the worksheet. Option Explicit Sub Testme01() dim myPWD as string myPWD = "top secret" worksheets("sheet9999").unprotect password:=mypwd 'do the real work worksheets("sheet9999").protect password:=mypwd end sub
Sure. But some of the features you try to use may not be available on a protected worksheet. A typical solution is to unprotect the worksheet, run the real code and the reprotect the worksheet. Option Explicit Sub Testme01() dim myPWD as string myPWD = "top secret" worksheets("sheet9999").unprotect password:=mypwd 'do the real work worksheets("sheet9999").protect password:=mypwd end sub
A Alan Jan 4, 2007 #3 Yes you can, use this code to 'sandwich' your code which will unprotect the sheet for the your code to run, then re-protect it when done, the password is optional, Sheet1.Unprotect ("password") 'Your code here Sheet1.Protect ("password") Regards, Alan.
Yes you can, use this code to 'sandwich' your code which will unprotect the sheet for the your code to run, then re-protect it when done, the password is optional, Sheet1.Unprotect ("password") 'Your code here Sheet1.Protect ("password") Regards, Alan.
G Gord Dibben Jan 4, 2007 #4 Depends what you want your macro to do but common method is to unprotect the sheet, do the deed then reprotect. Sub YourSub() ActiveSheet.Unprotect Password:="justme" 'your code to do the deed ActiveSheet.Protect Password:="justme" End Sub Gord Dibben MS Excel MVP
Depends what you want your macro to do but common method is to unprotect the sheet, do the deed then reprotect. Sub YourSub() ActiveSheet.Unprotect Password:="justme" 'your code to do the deed ActiveSheet.Protect Password:="justme" End Sub Gord Dibben MS Excel MVP