Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default protect sheet in VB

Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default protect sheet in VB

Mark, try this
ActiveSheet.Protect password:="123", DrawingObjects:=True, _
Contents:=True, Scenarios:=True

or with a input box to select a password

pw = InputBox("What password do you want to use ?")
ActiveSheet.Protect password:=pw, DrawingObjects:=True, _
Contents:=True, Scenarios:=True

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 97
** remove news from my email address to reply by email **
"Mark Howard" wrote in message
...
Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default protect sheet in VB

If you protect with code, and want a password, then the password is set with
code. There will be no prompt to set one.

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Password:= "mypass"
ActiveSheet.Unprotect Password:= "mypass"

Also, to unhide a sheet use .Visible = True

If someone tries to unprotect the sheet from the menu, they will get a
prompt for the password.

Hope this helps...Mike F


"Mark Howard" wrote in message
...
Hi,
I want to use the below line lock a sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True

and assign a password.

then the macro will hide the sheet.
ActiveWindow.SelectedSheets.Visible = False

Another Macro will unhide the sheet and then unlock it
with a password prompt.
ActiveWindow.SelectedSheets.Visible = False
ActiveSheet.Unprotect
but this does not work. I cannot assign a password on
protecting.

any ideas?




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
Bug - Protect Sheet ? Kevin Excel Discussion (Misc queries) 0 January 23rd 08 08:13 AM
How to protect all sheet ? vumian Excel Worksheet Functions 6 August 4th 06 06:02 PM
Protect Workbook Vs Protect Sheet Poor_pakistani New Users to Excel 4 May 25th 06 02:06 PM
Can I protect columns w/in a "List" using Protect Sheet? Diane Excel Discussion (Misc queries) 0 May 10th 06 03:30 PM
excel - macro code to open a protected sheet, enter passowrd, and then protect sheet arunjoshi[_5_] Excel Programming 1 May 2nd 04 03:50 PM


All times are GMT +1. The time now is 11:42 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"