username

  • Thread starter Thread starter RonB
  • Start date Start date
R

RonB

Guest
I have VBA code from developer library to get a user name

ie
Function FindUserName() As String
' This procedure uses the Win32API function GetUserName
' to return the name of the user currently logged on to
' this machine. The Declare statement for the API function
' is located in the Declarations section of this module.

Dim strBuffer As String
Dim lngSize As Long

strBuffer = String(100, " ")
lngSize = Len(strBuffer)

If GetUserName(strBuffer, lngSize) = 1 Then
FindUserName = Left(strBuffer, lngSize)
Else
FindUserName = "Name not available"
End If
End Function

However this code requires 'Declare statement'

To ease my life - can anyone give me an example of this 'Declare statement 'code
 
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 

Users who are viewing this thread

Back
Top Bottom