How to show current user name

  • Thread starter Thread starter LABMS
  • Start date Start date
L

LABMS

I have set up a spreadsheet to act as a form, on a
network, for several people to access. It would be
helpful if a cell on the sheet could automatically
display who opened the sheet. I think
BuiltinDocumentProperties can show the name of the LAST
user, but this is a little different.

Thank you
 
Hi LABMS!

You can use the following UDF:

Function USERNAME() As String
USERNAME = Application.USERNAME
End Function

This takes the User Name from the User Name given in Tools > Options >
General Tab

--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
Labms,

You can get what you are after using an auto_open macro in a module as
follows.

Sub Auto_Open()
Sheets(1).Cells(1, 1).Value = Environ("username")
End Sub


Robin Hammond
www.enhanceddatasystems.com
 
-----Original Message-----
Hi LABMS!

You can use the following UDF:

Function USERNAME() As String
USERNAME = Application.USERNAME
End Function

This takes the User Name from the User Name given in Tools > Options >
General Tab

-- Thanks very much - will try tommorrow & let you know if works out OK!
Regards
Norman Harker MVP (Excel)
Sydney, Australia
(e-mail address removed)
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.



.
 
I have tried to use the macro in a blank workbook, just
using cut and paste and dropping your text straight into
the "code" area.

It doesn't do anything, 'though it doesn't crash when I
next open the file; I suspect that I am missing something
like declaring a variable, or something of that nature -
it's probably obvious to you, but I am just not familiar
with the programming environment.

Please could you let me know if there is anything else I
need to add to the code for it to work?

Thanks once again.
 
Lee,

Norman's solution of using a udf is probably the simplest to implement
rather than trying to work out why auto_open is not firing as you suggest in
your email. (It's probably better to keep these things in the groups).

In your workbook, open the VB editor, insert a module, type in the following
2 functions:

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

Public Function WinUserName() As String
WinUserName = Environ("UserName")
End Function

In the cell you want to show the name in your spreadsheet, insert either of

=XLUserName()
or
=WinUserName()

HTH,

Robin Hammond
www.enhanceddatasystems.com
 
You are a diamond!

The problem was that I was dropping your stuff straight
into the "Microsoft Excel Objects" bit of the VB Editor,
and not into a module......like I know the difference?

Anyway, it works now. Will try your original suggestion as
well when get chance.

Many thanks.

LABMS
 

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