Get Computer Name using Excel VBA

Did you know that using Excel VBA you can get the computer name and print it to a cell.

I have used this before to monitor which computers on a network where accessing a staff performance system. I won’t publish the full code, but just the section that gets the computer name.

So, the code below would be entered as a new module. Note, it is just one line of code to get the name and print to the cell.

Public Sub Get_Computer_Name()

Cells(1,1) = Environ("computername")

End Sub

You could add in an extra line of code to then get the username of the person logged into the computer. Of course, this works when the pc requires a user to log in!

Leave a Reply

Your email address will not be published. Required fields are marked *