View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] tfraczak@gmail.com is offline
external usenet poster
 
Posts: 1
Default Protection Password Prompt Problem

I would like the prompt the user to input a password if the password
string variable does not already have a value.

This is the code I currently have.

Private Sub Worksheet_Activation(ByVal Target As Excel.Range)
Dim PWORD As String
If PWORD Is Nothing Then
PWORD = InputBox("Enter protection password:", "Set
Protection Password")
End If
ActiveWorkbook.Protect Password:=PWORD, Structu=True,
Windows:=True
ActiveSheet.Protect Password:=PWORD, DrawingObjects:=True,
Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlNoSelection
Application.DisplayFormulaBar = False
End Sub

Perhaps I should move the prompt to Sheet1_Initialize()?

Another problem I am having is that the PWORD string variable isn't
being recognized by .Protect and .Unprotect.

I have tried:

ActiveWorkbook.Protect Password:=PWORD, Structu=True, Windows:=True

and

ActiveWorkbook.Protect (PWORD, True, True)

They both do not work. Likewise for the ActiveWorkbook.Unprotect




I have only about a week's worth of self-VBA training. haha

Regards,
Tim