Get the Current Windows User ID in Excel or Access VBA
Question details
Get the current Windows login name in Excel or Access VBA so it can be used to filter records or reports.

- Product
- Microsoft Excel and Microsoft Access
- Device & OS
- Windows
- Scenario
- A user wants a VBA procedure to identify the current Windows user and show records assigned to that login name.
- Observed behavior
- The VBA procedure returns the current Windows login name for use in a filter or report.
Open the Excel workbook or Access database on Windows and make sure you can access its VBA editor. Check that the field used to assign records contains Windows login names.
Retrieve the Windows login name with VBA Environ
Use the UserName environment variable to capture the login name in an Excel or Access VBA procedure.
In Excel or Access, press Alt+F11 to open the Visual Basic Editor. Choose Insert > Module to create a standard module.
Add this procedure to the module: Sub CheckWindowsUser() Dim TheUser As String TheUser = Environ("UserName") Debug.Print TheUser End Sub Place the cursor inside the procedure and press F5. Press Ctrl+G to view the result in the Immediate window.
In Access, use TheUser in a report filter. For example, after assigning TheUser, call DoCmd.OpenReport "ReportName", acViewPreview, , "[AssignedTo] = '" & Replace(TheUser, "'", "''") & "'". Replace ReportName and AssignedTo with your actual report and text field names. In Excel, use TheUser as the criterion when filtering the column containing assigned login names.

Work with user-assigned spreadsheets in WPS Office
WPS Office is a free, lightweight alternative for opening and editing spreadsheets in a familiar interface. Its Microsoft Office format support makes it easy to move existing files into WPS; it does not replace Microsoft Access or resolve Access VBA issues.

Frequently Asked Questions
What does Environ("UserName") return?
It returns the value of the Windows UserName environment variable, typically the current login name. It does not necessarily return the user's email address or full display name.
How can I check the returned user name?
In the VBA editor, run a procedure containing Debug.Print Environ("UserName"), then press Ctrl+G to see the result in the Immediate window.
Can I use the login name to filter an Access report?
Yes. Pass a matching expression as the WhereCondition argument of DoCmd.OpenReport. Use the actual report and assigned-user field names, and escape apostrophes in the login name.
Is a VBA username filter enough to protect confidential records?
No. The UserName environment variable can be changed, and a report filter alone is not a security boundary. Use appropriate authentication and data-access controls for sensitive records.




