Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock 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

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
 
Replies continue below

Recommended for you

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