Insert user's logon name in to cell in worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to insert the Environ("User Name") in to cell B71, not sure how I go
about that?
 
Hello Ivory_Kitten,

VBA makes this information available through the global cal
Application.UserName. The value returned is a string.

Here is a UDF you can use. You will need to add a VBA module to projec
and place this code in it before you can use it.

1) Copy the code uing CTRL+C.
2) Open the Workbook you will be using.
3) Press ALT+F11 to open the VBA Editor
4) Press ALT+I to activate the Insert Menu.
5) Press M to insert a new Module into the Workbook.
6) Press CTRL+V to paste the code into the Module.
7) Press CTRL+S to save the Macro.
8) Press ALT+Q to close the VBA Editor.


Code
-------------------

Public Function UserName() As String
Application.Volatile
UserName = Application.UserName
End Function

-------------------


B71 formula >>> =UserName()
B71 will now show the name of the user currently logged on.

Sincerely,
Leith Ros
 
Hi

Sub InfoDeWindows()
With CreateObject("WScript.Network")
MsgBox "Por Windows_Scripting:" & vbCr & _
"Nombre del equipo: " & .ComputerName & vbCr & _
"Nombre del dominio: " & .UserDomain & vbCr & _
"Nombre del usuario: " & .UserName & vbCr & vbCr & _
"Por variables del entorno:" & vbCr & _
"Nombre del equipo: " & Environ("computername") & vbCr & _
"Nombre del dominio: " & Environ("userdomain") & vbCr & _
"Nombre del usuario: " & Environ("username")
End With
End Sub

Saludos :)
Atte.
?T Francisco T?
http://groups.msn.com/ExcelVbaMacrosOffice
http://groups.msn.com/dadyboy
http://search.microsoft.com/?mkt=es-ES

"El progreso debe ser un movimiento ordenado y racional hacia una meta
fija... y no un torbellino de direcciones falsas y encontradas."
 
All you need is

Public Function UserName() As String
Application.Volatile
UserName = Environ("UserName")
End Function

It is not a good idea to use APplication.Username as the user can change
that, there is no consistency. On a network, the login name is usually
protected against change by an individual.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
It's only working on my computer, when other users try to open my
spreadsheet, the username function does not work!?
 
Where did place the code for the username function ?
In the WB you sent them ?
Or in Personal.xls ?

NickHK
 
In a module in the worksheet

NickHK said:
Where did place the code for the username function ?
In the WB you sent them ?
Or in Personal.xls ?

NickHK
 
In a separate module or in a worksheet ?
The function must be in a module (not on a worksheet) and Public to use it
on a worksheet.

NickHK
 
My VBAProject is (CostCalculator.xlt) and the username function is in the
Modules folder, and is called Module1

This is the code which exists in Module1

Public Function UserName() As String
Application.Volatile
UserName = Application.UserName
End Function
 
What security setting do they use ?
Is the being fired at all ?
So if they enter "=UserName()" in a worksheet cell, what is the result ?

A few more details would help, instead of only "does not work".

NickHK
 
Macro Security is set to Low as we have Virus protection. When they open the
spreadsheet the field contains the data =username(). The result displayed in
the cell is #NAME!.
 
That means Excel cannot find the function "UserName", so the code is NOT on
a module, but on a worksheet or class module.
Move the code to a module in the WB in which it is used.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top