Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get username for excel 97 1

Status
Not open for further replies.

ChrisBurch

IS-IT--Management
Jul 3, 2001
184
AU
I've got a mixed bag of operating systems connecting to an NT4 network.

In my excel workbook, I'm grabbing the network username and using it for security. This is fine for my NT, Win 2000, and Citrix clients, but fails for my Win 98 clients. Is there anyway to access the network username that Win 98 clients are logging onto the system with.

Thanks. Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Hi Chris,

Try this out.
Copy/Paste this code to a module.

Then in the cell type
=returnusername()

Job's done.


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

Function ReturnUserName() As String
' returns the NT Domain User Name
Dim rString As String * 255, sLen As Long, tString As String
tString = ""
On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen > 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0
ReturnUserName = UCase(Trim(tString))
End Function


Regards,

Peter Remember- It's nice to be important,
but it's important to be nice :)
 
Thanks Peter,

That worked a treat.
Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Hi,

Glad to hear it worked for you.

Cheers,

Peter Remember- It's nice to be important,
but it's important to be nice :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top