Problem
We need to get the Windows user name using VBA. For example, in Excel we can display different info depending on the user opening the Excel file.
Solución
- Open the Visual Basic Editor: press Alt+F11.
- Copy the following subroutine into a module.
- Run the subroutines: press F5.
- Excel will display a pop up message showing the Windows user name.
Sub user()
MsgBox Environ("UserName")
End Sub
?Environ("Username")
Or we can capture and print the user name in a cell to customize the information displayed in that sheet or workbook.
Sub user_cell()
Sheets("Hoja1").Range("A1") = Environ("UserName")
End Sub
References
Nube de datos
No hay comentarios:
Publicar un comentario