Friday, August 21, 2015

How to get system info using excel vba

In some situations user need to know system information to automate their excel VBA automation. So, the users comes with below question.

Can I get System Info by Excel VBA ?


and the answer for this is "Yes"

Using below block of code user is able to get system info in their excel VBA Automation.


Sub System_Info()
' Author: Dreams24
' Written for VBA Tricks and tips blog
' https://vbatricksntips.com

Dim s_name, s_user, s_os, s_processor, s_userprofile, s_compspec, s_drive As String
Dim s_processor_cnt As Integer

' below line of code will pass value to string variables


    s_name = Environ("COMPUTERNAME")

    s_user = Environ("Username")
    s_os = Environ("OS")
    s_processor = Environ("PROCESSOR_IDENTIFIER")
    s_userprofile = Environ("USERPROFILE")
    s_compspec = Environ("ComSpec")
    s_drive = Environ("SystemDrive")
    
    ' below line of code will pass value to Integer variable
    
    s_processor_cnt = Environ("NUMBER_OF_PROCESSORS")
    
    MsgBox "Name of Computer is       : " & s_name & vbNewLine & vbNewLine & _
           "Username is               : " & s_user & vbNewLine & vbNewLine & _
           "Operating System is       : " & s_os & vbNewLine & vbNewLine & _
           "Processor Family is       : " & s_processor & vbNewLine & vbNewLine & _
           "Processor Count is        : " & s_processor_cnt & vbNewLine & vbNewLine & _
           "User Profile is           : " & s_userprofile & vbNewLine & vbNewLine & _
           "Computer Specification is : " & s_compspec & vbNewLine & vbNewLine & _
           "Operating System Drive is : " & s_drive, vbInformation, "System Information"

End Sub

Output:



No comments: