I am not sure how to get the following code to run under a macro. When I go into new macro and select Run Code and enter the Function GetUserName(). I try to run the code and receive a message stating that the function can not be found. I know that it is not found since it under a Private Declared Function but I am not sure how to change the code to get it to run as a macro. Please help.
Code:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function GetUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel19, "Random_Provider_List", "E:\Documents and Settings\" & fOSUserName & "\Desktop\Random_Provider_List.xls", , "Random_Provider_List"
Else
fOSUserName = vbNullString
End If
End Function