Results 1 to 2 of 2

Thread: VBA - HIding Excel (Different users)

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    VBA - HIding Excel (Different users)

    VB Code:
    1. Private Sub Workbook_Open()
    2. Sheets("HOME").Activate
    3. Dim bar As CommandBar
    4. For Each bar In Application.CommandBars
    5. bar.Enabled = False
    6. Next
    7. With Application
    8. .DisplayScrollBars = False
    9. .DisplayStatusBar = False
    10. .DisplayFormulaBar = False
    11. End With
    12. With ActiveWindow
    13. .DisplayHeadings = False
    14. .DisplayVerticalScrollBar = False
    15. End With
    16. Load UserForm1
    17. UserForm1.Show
    18. End Sub
    19.  
    20. Private Sub OK()
    21. If ComboBox1 = "ADMINISTRATION" Then
    22. If TextBox1 = "ICT" Then
    23. MsgBox "WELCOME STAFF", vbInformation, "HELLO"
    24. TextBox1 = ""
    25. Dim bar As CommandBar
    26. For Each bar In Application.CommandBars
    27. bar.Enabled = True
    28. Next
    29. With Application
    30. .DisplayStatusBar = True
    31. .DisplayFormulaBar = True
    32. .DisplayScrollBars = True
    33. .CommandBars("Standard").Visible = True
    34. .CommandBars("Formatting").Visible = True
    35. End With
    36. With ActiveWindow
    37. .DisplayGridlines = True
    38. .DisplayHeadings = True
    39. .DisplayVerticalScrollBar = True
    40. .WindowState = xlMaximized
    41. End With
    42. Me.Hide
    43. Else
    44. MsgBox "PLEASE TYPE CORRECT PASSWORD. USE CAPITAL LETTERS WHEN NEEDED.", vbInformation, "ACCESS DENIED!"
    45. TextBox1 = ""
    46. TextBox1.SetFocus
    47. End If
    48. End If
    49. If ComboBox1 = "CUSTOMER" Then
    50. TextBox1.Value = "NoPass"
    51. MsgBox "WELCOME TO TECHNO WORLD", vbInformation, "HELLO GUESTS!"
    52. TextBox1 = ""
    53. Me.Hide
    54. Else
    55. TextBox1 = ""
    56. End If
    57. End Sub
    58.  
    59. Private Sub Cancel()
    60. ActiveWindow.Close
    61. End Sub
    62.  
    63. Private Sub TextBox1_Change()
    64. TextBox1.PasswordChar = "*"
    65. End Sub
    66.  
    67. Private Sub UserForm_Initialize()
    68. With ComboBox1
    69. .AddItem "ADMINISTRATION"
    70. .AddItem "CUSTOMER"
    71. End With
    72. ComboBox1 = ""
    73. End Sub
    74.  
    75. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    76. If Cancel <> 1 Then
    77. Cancel = 1
    78. End If
    79. End Sub

    Can anyone help me make this code any shorter/simpler.

    Thanx in advance,
    Greyskull

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    A little shorter:
    VB Code:
    1. Private Sub Workbook_Open()
    2.     Sheets("HOME").Activate
    3.     SetExcelDisplay False
    4.    
    5.     Load UserForm1
    6.     UserForm1.Show
    7. End Sub
    8.  
    9.  
    10. Private Sub UserForm_Initialize()
    11.     With ComboBox1
    12.         .AddItem "ADMINISTRATION"
    13.         .AddItem "CUSTOMER"
    14.     End With
    15.     ComboBox1 = ""
    16. End Sub
    17.  
    18. Private Sub TextBox1_Change()
    19.     TextBox1.PasswordChar = "*"
    20. End Sub
    21.  
    22. Private Sub Cancel()
    23.     ActiveWindow.Close
    24. End Sub
    25.  
    26. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    27.     If Cancel <> 1 Then
    28.         Cancel = 1
    29.     End If
    30. End Sub
    31.  
    32.  
    33. Private Sub OK()
    34.     Select Case ComboBox1.Text
    35.     Case "ADMINISTRATION"
    36.         If TextBox1 = "ICT" Then
    37.             MsgBox "WELCOME STAFF", vbInformation, "HELLO"
    38.        
    39.             SetExcelDisplay True
    40.             ActiveWindow.WindowState = xlMaximized
    41.        
    42.             Me.Hide
    43.         Else
    44.             MsgBox "PLEASE TYPE CORRECT PASSWORD. " & _
    45.             "USE CAPITAL LETTERS WHEN NEEDED.", vbInformation, "ACCESS DENIED!"
    46.  
    47.             TextBox1.SetFocus
    48.         End If
    49.     Case "CUSTOMER"
    50.         TextBox1.Value = "NoPass"
    51.         MsgBox "WELCOME TO TECHNO WORLD", vbInformation, "HELLO GUESTS!"
    52.  
    53.         Me.Hide
    54.     End Select
    55.  
    56.     TextBox1 = ""
    57. End Sub
    58.  
    59. Private Sub SetExcelDisplay(ByVal blnEnableAll As Boolean)
    60.     Dim bar As CommandBar
    61.    
    62.     For Each bar In Application.CommandBars
    63.         bar.Enabled = blnEnableAll
    64.     Next
    65.    
    66.     With Application
    67.         .DisplayScrollBars = blnEnableAll
    68.         .DisplayStatusBar = blnEnableAll
    69.         .DisplayFormulaBar = blnEnableAll
    70.     End With
    71.    
    72.     With ActiveWindow
    73.         .DisplayHeadings = blnEnableAll
    74.         .DisplayVerticalScrollBar = blnEnableAll
    75.     End With
    76. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width