Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default VBA Code and Protection Sheet

Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default VBA Code and Protection Sheet


unlock the worksheet before running the code and lock it back up when
you are done...


Activesheet.Unprotect "<password"

'code here

Activesheet.Protect "<password"





amirstal wrote:
Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default VBA Code and Protection Sheet

Should I put this at the top of the code (just below its name: Sub
EoDProcess())?
"<password" - is where I should write the password that protects the
sheet, right?

Thanks.

wrote:
unlock the worksheet before running the code and lock it back up when
you are done...


Activesheet.Unprotect "<password"

'code here

Activesheet.Protect "<password"





amirstal wrote:
Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA Code and Protection Sheet

Hi,

if you want to change cells´values, you have to unprotect them, yes.
If you want to lock the sheet afterwards again, insert two rows in your
code:

Public Sub changingData
ActiveWorkbook.Worksheets("ProtectedSheet").Unprot ect "password"
...
(your code)
...
ActiveWorkbook.("ProtectedSheet").Protect "password"
End Sub

Regards,

Kai
Cologne, Germany

"amirstal" schrieb im Newsbeitrag
oups.com...
Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default VBA Code and Protection Sheet

I am a bit confused now with all the answers.
I protect the sheet thru Tools/Protection/Protect Sheet
so other users wont erase formulas by mistake.

Can the macro/VBA I run do the Unprotect Sheet function automatically
for me and re-protect it once the it is done running?

Amir


Jim Thomlinson wrote:
There are two possible solutions to your problem. If the sheet is protected
via code then you can add a paramter which will allow code to make any
changes it wants while still restricting the user. Something like this...

Sheets("Sheet1").Protect UserInterfaceOnly:=True, Password:="Tada"

If that is not how the sheet is protected then you need to unprotect the
sheet each time Code is going to make any changes to the sheet similar to
what has already been posted...

--
HTH...

Jim Thomlinson


"amirstal" wrote:

Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default VBA Code and Protection Sheet

What you wrote is exactly what you should do...

Sub Test()
ActiveSheet.Unprotect "password"

'your code here

ActiveSheet.Protect "password"
End Sub

where 'password' is your sheet password

when the sub is run, it will run through from beginning to end first
unprotecting, running your code, then finally reprotecting the sheet.

You can alternatively encompass a single line or any portion of code
with the Unprotect/Protect code we have given you.

Example:

Sub Test()

'beginning of your code

ActiveSheet.Unprotect "password"
Msgbox "just a portion of your code"
ActiveSheet.Protect "password"

'more of your code

End Sub

theSquirrel


amirstal wrote:
Should I put this at the top of the code (just below its name: Sub
EoDProcess())?
"<password" - is where I should write the password that protects the
sheet, right?

Thanks.

wrote:
unlock the worksheet before running the code and lock it back up when
you are done...


Activesheet.Unprotect "<password"

'code here

Activesheet.Protect "<password"





amirstal wrote:
Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default VBA Code and Protection Sheet

Thanks very much!

Amir

Jim Thomlinson wrote:
Yes VBA can be used to protect and unprotect a sheet...

Sub YourSub()
ActiveSheet.Unprotect Password:="password"
'your code here
ActiveSheet.Protect Password:="password"
End Sub

--
HTH...

Jim Thomlinson


"amirstal" wrote:

I am a bit confused now with all the answers.
I protect the sheet thru Tools/Protection/Protect Sheet
so other users wont erase formulas by mistake.

Can the macro/VBA I run do the Unprotect Sheet function automatically
for me and re-protect it once the it is done running?

Amir


Jim Thomlinson wrote:
There are two possible solutions to your problem. If the sheet is protected
via code then you can add a paramter which will allow code to make any
changes it wants while still restricting the user. Something like this...

Sheets("Sheet1").Protect UserInterfaceOnly:=True, Password:="Tada"

If that is not how the sheet is protected then you need to unprotect the
sheet each time Code is going to make any changes to the sheet similar to
what has already been posted...

--
HTH...

Jim Thomlinson


"amirstal" wrote:

Does Excel have a problem running a VBA code when the worksheet is
protected? If yes, is there a way to overcome it?

Thanks.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sheet protection code conflicts with Pivot Table "auto refresh" KG Excel Discussion (Misc queries) 6 December 21st 05 11:16 PM
Sheet Protection and XLA code Datasort Excel Programming 0 October 21st 05 06:18 PM
Sheet Protection and VBA Code TheRobsterUK Excel Discussion (Misc queries) 1 May 27th 05 05:18 PM
disabling the "view code" tab - sheet protection? neowok[_43_] Excel Programming 1 March 5th 04 02:48 PM
protection sheet and code ??? Linou[_4_] Excel Programming 0 October 29th 03 08:37 PM


All times are GMT +1. The time now is 07:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"