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:
My workaround was to use this function:
and then to insert a line to my other code like this:
The only issue I have with my workaround, is when the excel file is opened as Read-Only, I get the following error:
Does anyone have an idea how I can get this to work without any issues?
Thanks in advance
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
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