ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assigning User Names (https://www.excelbanter.com/excel-programming/306414-assigning-user-names.html)

depuyus[_8_]

Assigning User Names
 
I am working on a spreadsheet that will be used by various offices.
am trying to assign usernames so that when someone signs onto th
spreadsheet the appropriate office budget will be entered into th
beginning budget column. I was trying something like this:

DimvarInput As Integer
varInput = txtUser
Sheets("MainForm").Range("G5").Value = varInput
If txtUser = Mickey Mouse then
Sheets("MainForm").Range("G5") = $250,000
End If
If txtUser = Donald Duck Then
Sheets("MainForm").Range("G5") = $300,000 etc.


Is this close or am I going about this in the wrong way? I woul
appreciate any suggestions or someone steering me in the righ
direction. :

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Assigning User Names
 
Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function

Sib SetupBudget
Dim sUser

sUser = UserName
With Sheets("MainForm")
Select Case sUser
Case "Mickey Mouse": .Range("G5") = $250,000
Case "Donald Duck": .Range("G5") = $300,000
End Select
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"depuyus " wrote in message
...
I am working on a spreadsheet that will be used by various offices. I
am trying to assign usernames so that when someone signs onto the
spreadsheet the appropriate office budget will be entered into the
beginning budget column. I was trying something like this:

DimvarInput As Integer
varInput = txtUser
Sheets("MainForm").Range("G5").Value = varInput
If txtUser = Mickey Mouse then
Sheets("MainForm").Range("G5") = $250,000
End If
If txtUser = Donald Duck Then
Sheets("MainForm").Range("G5") = $300,000 etc.


Is this close or am I going about this in the wrong way? I would
appreciate any suggestions or someone steering me in the right
direction. :)


---
Message posted from http://www.ExcelForum.com/




Pyball[_25_]

Assigning User Names
 
Instead of using and API call you can get the user name by:

sUser = Application.UserNam

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Assigning User Names
 
Yes but that is changeable by the user, and so might break the code. The
NT/Windows 2000/XP login name isn't.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Pyball " wrote in message
...
Instead of using and API call you can get the user name by:

sUser = Application.UserName


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 05:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com