Macro to open view with a password
Here is an example:
Make Sheet1 VeryHidden:
Hit Alt+F11, go to Properties Visible 2-xlSheetVeryHidden
Place this code in Module1:
Sub Passwrd()
Dim i_pwd As String
i_pwd = InputBox("Please Enter Password to Unhide Sheet", "Unhide Sheet...")
If i_pwd = "" Then
Exit Sub
End If
'#1
Select Case (i_pwd)
Case Is = "Sheet1"
Worksheets("Sheet1").Visible = True
Sheets("Sheet1").Select
Case Else
MsgBox "Incorrect password; no action taken.", vbInformation, _
"Unhide Sheet..."
End Select
Exit Sub
Place this code in the Sheet named €˜ThisWorkbook (hit Alt+F11 to see this
object):
Private Sub Workbook_Open()
Module1.Passwrd
End Sub
Good luck,
Ryan---
"julief" wrote:
I am trying to have a macro open a view on a worksheet and really want to
have the worksheet protected. If i set a worksheet password the user is
prompted for it when they click on the macro button, is there any way i can
inlcude the password in the macro? I would also like to protect the
worksheet once the macro has been run.
The macro is as follows.
ActiveSheet.Unprotect
ActiveWorkbook.CustomViews("2 - Monday View").Show
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowSorting:=True
Range("L9").Select
End Sub
|