VBA Help - Pre Populate cell with users name, not their employee number

The Great SrH

Board Regular
Joined
Jan 16, 2015
Messages
179
Hi all,
I'm really struggling to have a cell pre-populate with the users full name. The only code I can find, returns the users employee number. See below:

Code:
Worksheets("test").Range("g9").Value = Environ("username")



My workaround was to use this function:

Code:
Function UserNames() As String
    Dim Users As Variant
    Dim sMsg As String
    Dim iIndex As Integer

    Users = ActiveWorkbook.UserStatus
    For iIndex = 1 To UBound(Users, 1)
        sMsg = Users(iIndex, 1) & vbLf
    Next iIndex
    'remove final line feed
    sMsg = Left(sMsg, Len(sMsg) - 1)
    UserNames = sMsg
End Function



and then to insert a line to my other code like this:


Code:
Worksheets("test").Range("d9").Value = UserNames
The only issue I have with my workaround, is when the excel file is opened as Read-Only, I get the following error:

Run-time error '1004':

Cannot access read-only document
'C:\Users\*Employee Number*\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\JTGBROUS\DocumentName.xlsm'.


Does anyone have an idea how I can get this to work without any issues?


Thanks in advance
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Did you try "Application.UserName"?

Environ("username") give the name of the account the user is logging in. In my case, it's not the Excel's user name.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top