Home |
Search |
Today's Posts |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() If ws.Name = "Main" or ws.Name = "IgnoreMe" Then Tim "LaDdIe" wrote in message ... Hiya Mike, I've just come across this code of yours. Can you tell me if it can ignore more than 1 ws and how, I tried to modify it without success. If ws.Name = "Main" Then "Mike Fogleman" wrote: OK, modify the code I gave you so far as this, In a regular module: Option Explicit Sub SheetMenu() UserForm1.Show Unload UserForm1 End Sub In the userform code module: Option Explicit Private Sub UserForm_Initialize() Dim ws As Worksheet For Each ws In Worksheets If ws.Name = "Main" Then 'do nothing Else Me.ListBox1.AddItem ws.Name End If Next End Sub Private Sub ListBox1_Click() Worksheets(ListBox1.Text).Visible = True UserForm1.Hide Worksheets(ListBox1.Text).Activate End Sub And change your worksheets code from Me.Previous to Worksheets("Main"). This is where you test the password so it should be here you send them back to the Main sheet if password fails. This will trigger the DeActivate Event and hide the columns. You may want to go so far as to re-hide the worksheet if password fails. I added those lines and remarked them. Private Sub Worksheet_Activate() Dim strPassword As String On Error Resume Next Me.Protect Password:="MANAGER" Me.Columns.Hidden = True strPassword = InputBox("Enter password to access DATA sheet") If strPassword = "" Then 'ActiveSheet.Visible = False Worksheets("Main").Select Exit Sub ElseIf strPassword < "MANAGER" Then MsgBox "Password Incorrect " 'ActiveSheet.Visible = False Worksheets("Main").Select Exit Sub Else Me.Unprotect Password:="MANAGER" Me.Columns.Hidden = False End If On Error GoTo 0 End Sub Private Sub Worksheet_Deactivate() On Error Resume Next Me.Columns.Hidden = True On Error GoTo 0 End Sub Mike F "Tony Borg" wrote in message ... Mike, Thanks for your reply. Here is the code I used to password protect the sheet. I just click on the sheet tab, view code and paste it in. I hope this helps. Regards -- TonyB 'CODE obtained from MS Community EXCEL Programmers 'Credit & Thanks to: Paul B Private Sub Worksheet_Activate() Dim strPassword As String On Error Resume Next Me.Protect Password:="MANAGER" Me.Columns.Hidden = True strPassword = InputBox("Enter password to access DATA sheet") If strPassword = "" Then Me.Previous.Select Exit Sub ElseIf strPassword < "MANAGER" Then MsgBox "Password Incorrect " Me.Previous.Select Exit Sub Else Me.Unprotect Password:="MANAGER" Me.Columns.Hidden = False End If On Error GoTo 0 End Sub Private Sub Worksheet_Deactivate() On Error Resume Next Me.Columns.Hidden = True On Error GoTo 0 End Sub "Mike Fogleman" wrote: Here is a start. In a regular module: Option Explicit Sub SheetMenu() UserForm1.Show End Sub You need a UserForm1 and a ListBox1 on that form. In the userform code module: Option Explicit Private Sub UserForm_Initialize() Dim ws As Worksheet For Each ws In Worksheets If ws.Name = "Main" Then 'do nothing Else Me.ListBox1.AddItem ws.Name End If Next End Sub Private Sub ListBox1_Click() Worksheets(ListBox1.Text).Visible = True End Sub This will show the selected sheet, but it is not the ActiveSheet yet. From here I need to know more about Some of the hidden worksheets have code which require a password to access/view. Some more detail and the code on how this is accomplished, will help me tie in the above code to the Worksheet code as it is activated. Mike F "Tony Borg" wrote in message ... Hi All, I would like to have a macro to assign to an icon. It would display a menu that shows the names of all available worksheets in a workbook. All sheets are hidden except the main worksheet. Some of the hidden worksheets have code which require a password to access/view. I would like the user to be able to select any one of the available worksheets but only one at any one time and if the selected sheet is password protected and they supply an incorrect password it returns them to the main worksheet. If any one can help i would be most grateful. Thank You. -- TonyB |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Is there a way to always view the drop-down menu arrow, without h. | Excel Discussion (Misc queries) | |||
Change the menu view | Setting up and Configuration of Excel | |||
Missing "Custom View" entry from View menu | Excel Discussion (Misc queries) | |||
i wana to know about Go to option that it is in view menu | Excel Discussion (Misc queries) | |||
View & Insert missing from menu bar!?!?! | Excel Discussion (Misc queries) |