Re: Username



The API example Tom posted should work fine for you in windows. Try pasting
it into a new module in a new project and try again. Earlier you said "
error Project or library not found", perhaps you have a missing reference
(Tools - references). If following works it would be highly indicative of a
missing ref.

MsgBox VBA.Interaction.Environ$("USERNAME")

If for you Environ("USERNAME") still doesn't work, ie it returns an empty
string but doesn't error, there's probably not much you can do about it. It
doesn't work for me either. However I get 10 returns if I run this -

Sub test()
Dim i As Long
On Error Resume Next
For i = 0 To 100
s = Environ(i)
If Len(s) Then
Debug.Print i, s
s = ""
End If
Next
End Sub

Regards,
Peter T


"Oldjay" <Oldjay@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AD8AD961-16A7-4680-AA6D-E5C0F2A3A2C2@xxxxxxxxxxxxxxxx
All computers have the same references and are running Excel 2003 SP3.
I tried the API and got the same error message at

GetUserName Buffer, BuffLen

"Tom Hutchins" wrote:

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?


.



Relevant Pages

  • Matching 3 criteria for a valid login?(Loging code included)
    ... Valid(username, pass and status) is the only way one can access the ... Private Sub Command1_Click ... Dim username As String ...
    (microsoft.public.vb.general.discussion)
  • Who can help me with this code ???
    ... UserName and Password, not just the password. ... >Private Sub Next_Click ... > Dim stLinkCriteria As String ...
    (microsoft.public.access.formscoding)
  • Re: Username
    ... Put the API declaration and function code in a VBA module (Insert>> Module ... string but doesn't error, there's probably not much you can do about it. ... End Sub ... Function UserName() As String ...
    (microsoft.public.excel.programming)
  • Re: What .NET classes are SLOW vs. API?
    ... you can't call an API from vb6? ... Dim dwHighDateTime As Int32 ... Public cAlternateFileName As String ... Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem with passing parameter
    ... Your declare for WriteFile is incorrect. ... Since you're using strings you'd alias this API with an "A". ... You can *not* pass a variant, even if it's type is string, to an API ... Public Sub WriteData ...
    (microsoft.public.vb.general.discussion)

Loading