Problem
We'd like to retrieve the current Windows user name in VBA. For instance, based on that value, we could track access, enable login, or personalize the information displayed in our files.
Solution
- We open the Microsoft Visual Basic Editor: Alt+F11.
- We copy the following subroutine.
- We run it pressing F5.
- A message box will display the name of the current user.
Sub username() MsgBox Environ("UserName") End Sub
?Environ("Username")We can store the user name in a cell.
Sub usuario() Sheets("Hoja1").Range("A1") = Environ("UserName") End Sub
No hay comentarios:
Publicar un comentario