ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting the systems username (https://www.excelbanter.com/excel-programming/274417-getting-systems-username.html)

Bruce A. Perry

Getting the systems username
 
Does anyone know how threw VBA to get the systems username
or login name. I can get the Application.UserName, but it
might not be the same for someone loging in at a diffrent
location?


Chip Pearson

Getting the systems username
 
Bruce,

Try something like

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

Function LogonName() As String
Dim S As String: S = String$(255, " ")
Dim L As Long: L = Len(S)
If GetUserName(S, L) Then
LogonName = Left(S, L - 1)
End If
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Bruce A. Perry" wrote in message
...
Does anyone know how threw VBA to get the systems username
or login name. I can get the Application.UserName, but it
might not be the same for someone loging in at a diffrent
location?




Brian

Getting the systems username
 
Try -

' Obtain the NT login id and use it as the user name in MS
Excel.
Application.UserName = Environ("USERNAME")


-----Original Message-----
Bruce,

Try something like

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

Function LogonName() As String
Dim S As String: S = String$(255, " ")
Dim L As Long: L = Len(S)
If GetUserName(S, L) Then
LogonName = Left(S, L - 1)
End If
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Bruce A. Perry" wrote in message
...
Does anyone know how threw VBA to get the systems

username
or login name. I can get the Application.UserName, but

it
might not be the same for someone loging in at a

diffrent
location?



.



All times are GMT +1. The time now is 11:15 PM.

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