|
-
Mar 24th, 2004, 08:09 AM
#1
Thread Starter
Hyperactive Member
VBA - HIding Excel (Different users)
VB Code:
Private Sub Workbook_Open()
Sheets("HOME").Activate
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
With Application
.DisplayScrollBars = False
.DisplayStatusBar = False
.DisplayFormulaBar = False
End With
With ActiveWindow
.DisplayHeadings = False
.DisplayVerticalScrollBar = False
End With
Load UserForm1
UserForm1.Show
End Sub
Private Sub OK()
If ComboBox1 = "ADMINISTRATION" Then
If TextBox1 = "ICT" Then
MsgBox "WELCOME STAFF", vbInformation, "HELLO"
TextBox1 = ""
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
With Application
.DisplayStatusBar = True
.DisplayFormulaBar = True
.DisplayScrollBars = True
.CommandBars("Standard").Visible = True
.CommandBars("Formatting").Visible = True
End With
With ActiveWindow
.DisplayGridlines = True
.DisplayHeadings = True
.DisplayVerticalScrollBar = True
.WindowState = xlMaximized
End With
Me.Hide
Else
MsgBox "PLEASE TYPE CORRECT PASSWORD. USE CAPITAL LETTERS WHEN NEEDED.", vbInformation, "ACCESS DENIED!"
TextBox1 = ""
TextBox1.SetFocus
End If
End If
If ComboBox1 = "CUSTOMER" Then
TextBox1.Value = "NoPass"
MsgBox "WELCOME TO TECHNO WORLD", vbInformation, "HELLO GUESTS!"
TextBox1 = ""
Me.Hide
Else
TextBox1 = ""
End If
End Sub
Private Sub Cancel()
ActiveWindow.Close
End Sub
Private Sub TextBox1_Change()
TextBox1.PasswordChar = "*"
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "ADMINISTRATION"
.AddItem "CUSTOMER"
End With
ComboBox1 = ""
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If Cancel <> 1 Then
Cancel = 1
End If
End Sub
Can anyone help me make this code any shorter/simpler.
Thanx in advance,
Greyskull
-
Mar 27th, 2004, 07:43 PM
#2
A little shorter:
VB Code:
Private Sub Workbook_Open()
Sheets("HOME").Activate
SetExcelDisplay False
Load UserForm1
UserForm1.Show
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "ADMINISTRATION"
.AddItem "CUSTOMER"
End With
ComboBox1 = ""
End Sub
Private Sub TextBox1_Change()
TextBox1.PasswordChar = "*"
End Sub
Private Sub Cancel()
ActiveWindow.Close
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If Cancel <> 1 Then
Cancel = 1
End If
End Sub
Private Sub OK()
Select Case ComboBox1.Text
Case "ADMINISTRATION"
If TextBox1 = "ICT" Then
MsgBox "WELCOME STAFF", vbInformation, "HELLO"
SetExcelDisplay True
ActiveWindow.WindowState = xlMaximized
Me.Hide
Else
MsgBox "PLEASE TYPE CORRECT PASSWORD. " & _
"USE CAPITAL LETTERS WHEN NEEDED.", vbInformation, "ACCESS DENIED!"
TextBox1.SetFocus
End If
Case "CUSTOMER"
TextBox1.Value = "NoPass"
MsgBox "WELCOME TO TECHNO WORLD", vbInformation, "HELLO GUESTS!"
Me.Hide
End Select
TextBox1 = ""
End Sub
Private Sub SetExcelDisplay(ByVal blnEnableAll As Boolean)
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = blnEnableAll
Next
With Application
.DisplayScrollBars = blnEnableAll
.DisplayStatusBar = blnEnableAll
.DisplayFormulaBar = blnEnableAll
End With
With ActiveWindow
.DisplayHeadings = blnEnableAll
.DisplayVerticalScrollBar = blnEnableAll
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|