Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Grabbing a User's Name from Excel.

Grabbing a User's Name from Excel

by Allen Wyatt
(last updated June 23, 2018)

7

Mark has a worksheet where he wants to record the name of a user, but rather than asking the user to fill in a form, he wants to automatically grab their username from Excel.

The username that a person sets in Excel when first installing the software or when changing the general options for the program cannot be accessed via formula. Instead, you need to use a macro to access the information and then make it available to your worksheet. This is possible through the use of a user-defined function. Consider the following simple example:

Function GetUserName()
    GetUserName = Application.UserName
End Function

Note that the macro does nothing more than to access the UserName property of the Application object. You use this function in your worksheet in the following manner:

=GetUserName()

With this simple formula in a cell, the username is displayed in the cell.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9814) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Grabbing a User's Name from Excel.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Quickly Inserting a New Worksheet

Want a quick way to insert a worksheet? There's nothing faster than using the handy shortcut.

Discover More

Detecting an Open Dialog Box

Macros can be used to perform all sorts of tasks within Word. Some tasks can even occur at whatever time interval you ...

Discover More

Counting Words in Comments

Word makes it easy to calculate the number of words in a document. If you want to count words only in your comments, then ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Losing Data in a Shared Workbook

When you create a shared workbook, you run the risk of losing some of the data in that workbook. Here's a discussion ...

Discover More

Odd Arrow Key Behavior

Press the up or down arrow keys, and you expect Excel to change which cell is selected. If this doesn't occur on your ...

Discover More

Getting Stock Information into Excel

Excel is a great tool for analyzing financial information. If you want to do some analysis using stock information, it is ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 9 + 2?

2016-05-11 13:22:19

Dex Luther

This worked perfectly.

This shows a person's name as "Lastname, Firstname". I was wondering if there was a way to switch it to show "Firstname Lastname"


2015-12-16 18:29:36

Dawn

Could something similar be used to pull in specific Workbook Properties?

For example: I'd like to auto-populate a cell with the contents of the "Tags" (sometimes also called "Keywords") property field as shown on the Excel Info Properties view.


2015-10-14 04:17:14

Gareth Crothers

I'm looking to to add the user name of the person who adds information to a Excel document from an in house server.

Similar to the date formulae where it retrieves the date from your Mac, is there a way I can create something to retrieve the user name of their Mac?

Thanks in advance!


2015-04-06 11:36:10

Scott Renz

Thanks, Larry Conrad,
What is "WinNT"?
My computer doesn't seem to like it.


2015-04-06 08:46:50

Larry Conrad

Here is a code snippet I use to get User info from a network id.

Dim UsrDomain As String
Dim UsrId As String
Dim UsrName As String
Dim ADUser As Object

UsrDomain = Environ("USERDOMAIN")
UsrId = Environ("USERNAME")
Set ADUser = GetObject("WinNT://" & UsrDomain & "/" & UsrId)

UsrName = Mid(ADUser.FullName, InStr(1, ADUser.FullName, ",") + 2, 30) & " " & _
Left(ADUser.FullName, InStr(1, ADUser.FullName, ",") - 1)


2015-04-04 09:36:07

Gerhard Schweizer

It should be mentioned that this username is just the name within MS Office, not (necessarily) the Windows username. To retrieve the latter, another function must be used


2015-04-04 05:37:43

ravi kumar mathur

very good and useful tip, thanks


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.