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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pick up "Username"

Status
Not open for further replies.

Binnit

Technical User
Apr 28, 2004
627
US
In MS Access there is a function Environ("username") which enables you to pick up the user name details, I cannot find a similar function within Excel, anybody know if there is a similar/alternative function I can use?

I am using Office 97

Thanks

If IT ain’t working Binnit and Reboot
 
In Excel 2000 the same function exists, I'm not sure about 97, have you tried it in 97?
 
Molby
Yes sort of strange results...

If I put =Environ("username") directly in a cell it creates a #Name error.

If I enter ?Environ("username") in the VBEditor immediate window, it returns the correct user name

I have tried to assign the result to a string "UserID" and then entered =UserID in a cell but same #Name error occurs.

Any further thoughts?

If IT ain’t working Binnit and Reboot
 
Hello
You can use either of these user defined functions depending on what you want.


Private Declare Function api_GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" _
(ByVal lpbuffer As String, nsize As Long) As Long

' Function to get back the Network User ID
Public Function GetUser()
Dim Buff As String
Dim BuffSize As Long
Dim result As Long
BuffSize = 256
Buff = Space$(BuffSize)
result = api_GetUserName(Buff, BuffSize)
GetUser = Trim$(Buff)
End Function

' Function to get back Username
Function USRName()
USRName = Application.UserName
End Function


hth

Best Regards
Andreas
using xl2000 on win2k
 
Binnit, you can't use that in a cell. Assign it to a value in a macro.
Range("a1").value =Environ("username")
 
Andreas / Milby
Umm still struggling over this, have tried Andreas 2nd option but appear to be having some conflict problems with running 2 instances of Excel through Fat and Thin client on the same machine. It is returning something like the user name but I'm not sure of its origin because its not the correct environment login name, it appears to be similar to the details stored with the general user information found within the Tools/Options/General menu?

Molby
Have also tried you latest option but am getting an error on start up, I believe I can resolve this and will post back.

Thanks for your help so far.... may need more soon!

If IT ain’t working Binnit and Reboot
 
Mulby
Have now resolved the start up problem and also have now captured login name as required, next step to build the lookup values.

Looking good for a successful solution

If IT ain’t working Binnit and Reboot
 
Mulby / Andreas
Have now completed this and used the assignment method in your last post.

Thank you both for your suggestions



If IT ain’t working Binnit and Reboot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top