Adding Usernames

mrbeanyuk

Board Regular
Joined
Nov 30, 2005
Messages
212
I have a coding that was provided kindly by you guys. However, I would like to add additional usernames but am unsure how?

The username currently is muirheadn110 and I need to add say another 5. The current coding is as follows:

Private Sub Workbook_Open()
Dim user_name As String
Dim FBR As Long
user_name = InputBox("Please enter your ISIS username to access the Project HERMES interface. Please note that this spreadsheet should not be amended in any way.", "PROJECT HERMES LOGIN", "")
If user_name <> "muirheadn110" Then
ActiveWorkbook.Close (0)
End If
With Sheets("Homepage")
FBR = .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
.Cells(FBR, 2) = user_name
.Cells(FBR, 1) = Now
End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
Code:
Private Sub Workbook_Open() 
Dim user_name As String 
Dim FBR As Long 
user_name = InputBox("Please enter your ISIS username to access the Project HERMES interface. Please note that this spreadsheet should not be amended in any way.", "PROJECT HERMES LOGIN", "") 
If accept_name(user_name) = false Then 
ActiveWorkbook.Close (0) 
exit sub
End If 
With Sheets("Homepage") 
FBR = .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row 
.Cells(FBR, 2) = user_name 
.Cells(FBR, 1) = Now 
End With 
End Sub

function accept_name(uname as string) as boolean
select case ucase(uname)
case "MUIRHEADN110"
   accept_name = true
case "ANOTHERUSERNAME"
  accept_name = true
case "ANOTHERAGAIN"
  accept_name = true
case "GOONONEMORE"
  accept_name = true
case "FINALUSER"
  accept_name = true
case else
  accept_name = false
end select
end function

I have modified your code so that it calls a function with the username provided. Within this function, the username is converted to all upper case, then contrasted with several caveats on a selet case statement to determine if the username is acceptable. If so, the function will return true, otherwise it will return false.

You can add additional usernames by using the line

Code:
case "user name here"
  accept_name = true

within the select case statement in that function.

Hope this is of help to you

all the best, patrick
 

Forum statistics

Threads
1,141,587
Messages
5,707,247
Members
421,498
Latest member
matinebi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top