Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Password Protection

I am wondering if it is possible to have a protect macro that has a hardcoded
password so that a user can run the macro and it will protect with the same
macro every time, but the have an unprotect macro that makes people type the
password in. I currently have an unprotect macro, but it when the protected
sheet has a password has a password on, it errors out.

Any suggestions?

Currently I have this
To Protect:
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True,
Scenarios:=True

To Unprotect:
ActiveSheet.Unprotect DrawingObjects:=True, Contents:=True, Scenarios:=True

When you run the protect macro and then the unprotect macro it causes an
object or application defined error.

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Password Protection

Hi W,

Try something like:

'=============
Public Sub Tester()
Dim PWORD As String

PWORD = InputBox(Prompt:="Please type the password")

ActiveSheet.Unprotect Password:=PWORD, _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True
End Sub
'<<=============


---
Regards,
Norman


"WBTKbeezy" wrote in message
...
I am wondering if it is possible to have a protect macro that has a
hardcoded
password so that a user can run the macro and it will protect with the
same
macro every time, but the have an unprotect macro that makes people type
the
password in. I currently have an unprotect macro, but it when the
protected
sheet has a password has a password on, it errors out.

Any suggestions?

Currently I have this
To Protect:
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True,
Scenarios:=True

To Unprotect:
ActiveSheet.Unprotect DrawingObjects:=True, Contents:=True,
Scenarios:=True

When you run the protect macro and then the unprotect macro it causes an
object or application defined error.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Password Protection

I have found that if I change the Unprotect Macro to simply read:
ActiveSheet.Unprotect

It works just fine. ( I don't know if I can "un-post" this message, so
apologies if I wasted anyone's time.)

"WBTKbeezy" wrote:

I am wondering if it is possible to have a protect macro that has a hardcoded
password so that a user can run the macro and it will protect with the same
macro every time, but the have an unprotect macro that makes people type the
password in. I currently have an unprotect macro, but it when the protected
sheet has a password has a password on, it errors out.

Any suggestions?

Currently I have this
To Protect:
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True,
Scenarios:=True

To Unprotect:
ActiveSheet.Unprotect DrawingObjects:=True, Contents:=True, Scenarios:=True

When you run the protect macro and then the unprotect macro it causes an
object or application defined error.

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Password Protection

Don't forget to put

ActiveSheet.Unprotect Password:="123"...

You need the same password to unprotect.

"WBTKbeezy" wrote:

I am wondering if it is possible to have a protect macro that has a hardcoded
password so that a user can run the macro and it will protect with the same
macro every time, but the have an unprotect macro that makes people type the
password in. I currently have an unprotect macro, but it when the protected
sheet has a password has a password on, it errors out.

Any suggestions?

Currently I have this
To Protect:
ActiveSheet.Protect Password:="123", DrawingObjects:=True, Contents:=True,
Scenarios:=True

To Unprotect:
ActiveSheet.Unprotect DrawingObjects:=True, Contents:=True, Scenarios:=True

When you run the protect macro and then the unprotect macro it causes an
object or application defined error.

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Password Protection

Hi W,

Please replace my suggested code with the following version:

'=============
Public Sub Tester()
Dim PWORD As String

PWORD = InputBox(Prompt:="Please type the password")

On Error Resume Next
ActiveSheet.Unprotect Password:=PWORD

If Err.Number < 0 Then
MsgBox "The password was not recognised"
End If
On Error GoTo 0
End Sub
'<<=============

---
Regards,
Norman


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
Password protection in macro ( Anybody can view my password in VB Sherees Excel Discussion (Misc queries) 2 January 24th 10 10:05 PM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
Password Protection DNA Excel Discussion (Misc queries) 0 May 3rd 06 01:59 PM
Password Protection ralph Excel Discussion (Misc queries) 2 April 17th 06 09:56 PM
VB password protection?? jwflutterby Excel Programming 2 July 20th 04 03:40 AM


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

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"