PutUsername: Dynamically Put Username Into String

Don’t you wish there was a simple way to put an individual’s username into a formula? A good use case is helping an individual navigate to say a company OneDrive, SharePoint, Box folder, or even their own Download folder.

PutUsername

Function PutUsername(GivenString As String) As String
    PutUsername = Replace(GivenString, "%USERNAME%", Environ("USERNAME"), , , vbTextCompare)
End Function
ParameterDescription
GivenStringThis is the string to put the username into.
The string should include %USERNAME%, which is substituted with the Excel user’s actual Windows username.
Note %USERNAME% is not case sensitive.

Examples

All examples assume the Windows username looking at the Excel file is AHavas.

=PutUsername("Hello %USERNAME%, how are you?")

If you place the above formula into cell A1, it will read Hello AHavas, how are you?

=HYPERLINK(PutUsername("C:\Users\%USERNAME%\Downloads\"), "Link to your downloads folder")

If you please the above formula into cell A2, it will read “Link to your downloads folder”, and it will be a clickable link to the individual’s Windows download folder.

Scroll to Top