GetUserName

March 2nd, 2007

Sometimes, there's a need to get the LAN userid of the currently logged on user. Here's how to do that with VBA

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

Function CurrentUserName() As String
    Dim lReturn As Long
    Dim strBuffer As String
   
    strBuffer = Space(255)
    lReturn = GetUserName(strBuffer, 255)
    CurrentUserName = Mid(strBuffer, 1, Len(Trim(strBuffer)) - 1)
End Function

Posted in Excel, VBA | No Comments




No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment



(C) by Virgilio Adriano. All rights reserved. Powered by WordPress.
Entries and comments feeds.
It took 0.340 seconds to load this page.