Protect Sheet with VBA

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 1
Reputation: halem2 is an unknown quantity at this point 
Solved Threads: 0
halem2 halem2 is offline Offline
Newbie Poster

Protect Sheet with VBA

 
0
  #1
Sep 16th, 2004
Hi:

I have a workbook that has several sheets. One sheet called FORM is password protected (by me). I have a macro that clears all sheets but when it gets to FORM it prompts for the password (which I don't wan't to give to my users).

Is there a way to pass the password to the sheet as the macro is running?

thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1
Reputation: mkrasnop is an unknown quantity at this point 
Solved Threads: 0
mkrasnop mkrasnop is offline Offline
Newbie Poster

Re: Protect Sheet with VBA

 
0
  #2
Feb 8th, 2008
Originally Posted by halem2 View Post
Hi:

I have a workbook that has several sheets. One sheet called FORM is password protected (by me). I have a macro that clears all sheets but when it gets to FORM it prompts for the password (which I don't wan't to give to my users).

Is there a way to pass the password to the sheet as the macro is running?

thanks
See below. You also need to protect the VBA module so the user can't see the password:
In project explorer, right click on the modue and select "[module name] properties...". Then click on the protect tab and check lock project for viewing and add a password.

Change yourpassword with any password you want.

' Unprotect the FORM sheet so that VBA can write to it
Sheets("FORM").Unprotect Password:="yourpassword"

' Protect the FORM sheet (change the options after the password to suit your needs)
Sheets("FORM ").Protect Password:="yourpassword", _
DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: vba_dev is an unknown quantity at this point 
Solved Threads: 0
vba_dev vba_dev is offline Offline
Newbie Poster
 
0
  #3
28 Days Ago
This simple code will solve your problem.
I assume that sheet1 is your form sheet which you want to protect and only access through code.

sheet1.protect "password", userinterfaceonly:=true

Please note that sheet1 in given in "Microsoft Excel Object" Index in Visual Basic Editor.

Visit my blog if you are willing to download an ebook on Excel.
http://total-ebooks4free.blogspot.com/
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC