Tuesday, May 01, 2007

Get Computer Name

Get Computer Name / Get User Name

Environ$ can be used to retrieve information from an operating system environment variable

Sub Get_Environmental_Variable()

Dim sHostName As String
Dim sUserName As String

' Get Host Name / Get Computer Name

sHostName = Environ$("computername")

' Get Current User Name

sUserName = Environ$("username")

End Sub

In Dot Net it can be achieved by http://dotnetdud.blogspot.com/2007/06/get-computer-name-in-net.html




  1. Hello - I need some assistance if you can? I have an excel file that has some kind of VBA security built into it that reads the computer name. I recently switched computers (upgraded) and now can't open this excel file. The author of the excel file is no longer here so I can't ask him how to change the info...is there a work around? Thank you.

  2. I have an excel file that has some kind of VBA based security in it...it reads the computer name. This was developed for me at a work computer - and I have recently changed computers and need to get this file operational on the new computer...unfortunately the developer of this excel file is no longer here so I can't ask him what i need to change...I've tried making the computer name the same (via System name change) but that did not work...any advice to turning off this security feature? Thank you,

  3. Hi Phillip

    Do you have access to the VBA code of the excel file. Then we can modify it to work for your computer.

    There are many ways to 'tag' a program to a particular computer

    1. ComputerName
    2. Static IP address
    3. Physical Address of Computer
    4. Volume Number of Hard Disk

    The above are few ways to lock the program to a machine. Since you have changed the ComputerName already, it means that the code is not checking for the name.

  4. Anonymous7:40 PM

    Excellent. Just what I was looking for. One of the macros I'm running requires software that only certain computers have a license for. This allows me to ensure that if that computer doesn't have a license (based on computer names) the macro will not run. Thanks.

  5. Hello, its probablly been a while since someone actually post here but ill ask anyways. Ive been all over the net looking for a VBA script to run and gather system info such as cpu/ram/hard drive. Along with that info geing captured id like it to be transfered over to my excel doc. is there anything or anywhere i can find that script or somthing like it. Any thing is much appreciated. Thanks

  6. Anonymous10:59 PM

    This is a very good example. Short and sweet. :)
    I looked at some other posts also on the same topic but they all used the GetComputerName functions etc which is not so easy to use.

  7. can you help me to get host id of computer in excel.
    I want to create an excel file that is locked to host id of computer


Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.