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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel -NT Username 3

Status
Not open for further replies.

lochmant

Technical User
Apr 3, 2003
3
US
Does anyone know how I can get the Windows NT User Logon Name using VBA in MS Office? (I already posted this in the access Forum)
 
If Environ("Username") doesn't do it it's an API call which I don't have a record of!

;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
This should do it:

Function GetUser
GetUser = Environ("Username")
End Function

Sub Test
MsgBox GetUser
End Sub

Regards
 
Have you tried Environ("USER") ?

Hope This Help
PH.
 
View FAQ faq707-4296 - List environment variables

The API function for this is:

[tt]Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function ReturnComputerName() As String
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetComputerName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen > 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnComputerName = UCase(Trim(tString))
End Function
[/tt]

I hope that these posts have helped you!



Peace!! [americanflag] [peace] [americanflag]

Mike

Didn't get the answers that you wanted? Take a look at FAQ219-2884
 
I just had to give a star to Loomah for the Environ("Username") and also to DrBowes for demonstrating how to use it as a function. This has helped me solve a problem I had with obtaining username, computername etc
I now use:

Function GetUser()
GetUser = Environ("Username")
End Function

Function GetComputer()
GetComputer = Environ("Computername")
End Function

Function GetOS()
GetOS = Environ("OS")
End Function

Is there a list anywhere that shows what arguments you can use with environ ? I couldn't find anything in the help
 
In a console windows execute the SET command.
All the words at the left of an equal sign (=) are candidate
 
Thanks for the quick reponse PHV. That is just what I was looking for. A star for you to as I believe this will be helpful to many users.
 
waynerenaud - See Mike's (Bowers74) post - his 1st comment is a link to a FAQ on just this subject

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top