In most of the online resource I can find usually show me how to retrieve this information in VBA. Is there any direct way to get this information in a cell?
For example as simple as =ENVIRON('User')
(which did not work)
1. Press Alt + F11 keys to enable Microsoft Visual Basic for Applications window, click Insert > Module, then copy and paste below VBA code to the Module window. VBA: Insert username. You can change the range A1: D5 in VBA code to meet your need.
The name box is the box at left end of the formula bar that identifies the selected cell, chart item, or drawing object. The Name Box displays the cell reference of the active cell. The Name Box can also be used to assign names to cells or ranges of cells.
To get the current worksheet's name, you can use the function with or without the optional reference argument, referring to any cell on the current tab. You can also get information about any other worksheet by referring to a cell on that sheet.
Based on the instructions at the link below, do the following.
In VBA insert a new module and paste in this code:
Public Function UserName()
UserName = Environ$("UserName")
End Function
Call the function using the formula:
=Username()
Based on instructions at:
https://support.office.com/en-us/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f
Without VBA macro, you can use this tips to get the username from the path :
=MID(INFO("DIRECTORY"),10,LEN(INFO("DIRECTORY"))-LEN(MID(INFO("DIRECTORY"),FIND("\",INFO("DIRECTORY"),10),1000))-LEN("C:\Users\"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With