Is there a way to get the name of the computer in VBA?
We have created “GetComputerUserName” macro to find the computer and user name. We can run the macro by clicking “Submit” button. Macro will extract computer name in cell C10 and user name in cell C11. Environ function returns the string value associated with environment variable of the operating system.
Click on the Start button. In the search box, type Computer. Right click on This PC within the search results and select Properties. Under Computer name, domain, and workgroup settings you will find the computer name listed.
Excel has the same OperatingSystem object but under the Application class, so to get the same info in Excel you use Application. OperatingSystem . A full reference of the objects available to you is provided in the Object Browser (F2 from within the VBA editor.)
Dim sHostName As String ' Get Host Name / Get Computer Name sHostName = Environ$("computername")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With