Welcome to Office Zealot Sign in | Join | Help
Retrieve the login name of the current user in Excel using VBA (with Vista/Excel 2007 screencast)

How do I retrieve the login name of the current user in Excel or VBA? This has to be one of the most common questions asked by people building Office-based applications. Though Charles covered it pretty throughly a couple of years ago, I thought I'd give it some more coverage. Seems as though many people still go the API route when the VBA Environ function is so simple and handy.

The short answer is to write a simple VBA function that calls Environ:

Function UserName() As String
     UserName = Environ("USERNAME")
End Function

Just for fun, I created a screencast that shows how to do this. If you're never written a VBA macro in your life, check it out as it'll show you step by step what you need to do. If you know VBA like the back of your hand but haven't checked out Windows Vista or Excel 2007, you might want to check it out to see what they look like.

Posted: Wednesday, January 03, 2007 8:43 AM by hansen
Filed under: , ,

Comments

No Comments

Anonymous comments are disabled