Username
On the computers where this code does not work there is probably a needed
reference missing (to see what references have been added, select Refernces
from the Tools menu in the Excel Visual Basic Editor). I think the missing
refernce is either 'Visual Basic for Applications' or 'Microsoft Excel 11.0
Object Library' (you may have a different version than 11.0).
Here is another way to retrieve the user's LAN ID using an API call:
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Function UserName() As String
Dim Buffer As String * 100
Dim BuffLen As Long
On Error GoTo UNerr
BuffLen = 100
GetUserName Buffer, BuffLen
UserName = Left(Buffer, BuffLen - 1)
Exit Function
UNerr:
UserName = vbNullString
End Function
Sub AAAAA()
MsgBox UserName()
End Sub
Hope this helps,
Hutch
"Oldjay" wrote:
I have the following code that works on some computer but not on others
It gives the error Project or library not found
Public Function UserName()
UserName = Environ("USERNAME")
End Function
Also tried UserName = Environ$("USERNAME")
What do I have to add?
|