View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Getting Windows user (Account) from a VBA routine

Jacques,

You can get the user's logon name with the following code:

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

Sub AAA()
Dim UName As String * 255
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
Msgbox UName
End Sub

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





"Jacques Brun" wrote in
message
...
I want to provide an audit trail of who did what and when for a

shared Excel application. The "Application.Username"
returns an Id that can easily be forged (Tools Options etc.).

I've been looking for a way to retrieve the userid (account)
used to log on to the operating system (Windows) but so far i

didn't found anything in my documentation or on the Web.
Does anybody knows a solution ? Thanks