Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatic user id in Excel

  • Thread starter Thread starter -
  • Start date Start date
Status
Not open for further replies.

Guest
I would like to know if there is a way to get the user id, in a procedure, of the person who opens an Excel spreadsheet in order to display fields appropriate to the user. Thanks in advance.

Todd
 
If you are using NT, 2000 or possibly XP:
Code:
Dim sUser As String

sUser = UCase(Environ("username"))
[\code]
This utilizes the use of the USERNAME environment variable. Another way to accomplish this is using the API:
[code]
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetCurrentUser() As String
    Dim lpBuff As String * 25
    Dim ret As Long
    ret = GetUserName(lpBuff, 25)
    GetCurrentUser = UCase(Left(lpBuff, InStr(lpBuff, Chr(0)) - 1))
End Function
Hope this helps... DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top