A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Environ is a VB/VBA function - the other can be used with any language.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
I used previously this API function
Declare Function wu_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function GetUserName() As Variant
Dim strUserName As String, lngLength As Long, lngResult As Long
strUserName = String$(255, 0)
lngLength = 255
lngResult = wu_GetUserName(strUserName, lngLength)
GetUserName = Left(strUserName, InStr(1, strUserName, Chr(0)) - 1)
End Function
Similarly, you could use : Environ("username")
Both function return the same string that needs to be the current user/window session logged on that pc.
Any comment ?
Regards
JY
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Environ is a VB/VBA function - the other can be used with any language.
Hi Hans
I suspected something like that ...
Maybe it is also historical, that the Environ function was only released later ?
Regards
JY
Hi Bernie
For Application.UserName, I know that you could just use
Application.UserName= "Mickey Mouse" before saving any file, ( could be usefull at some time)
Therefor, I use normally the API function
Thank you
Regards
JY
Someone who is computer-savvy could change the username environment string, so Environ("username") is not 100% dependable. As far as I know, it's far more difficult (if possible at all) to change the result of the API function.
They return the same information, just through different mechanisms. Note that
Application.UserName
may differ, since the user gets to set that in Excel options.