Environ Variable

  • Environ variable in VBA Macros
  • This variable consists of 38 Elements
  • We can retrieve those elements by loop through the Environ Expression argument
  • This environ variable returns all the information about the SYSTEM\COMPUTER
  • We can use expression value upto 38, means this variable consists of 38 elements
  •  

    Retrieve all the data from environ variable

     

    Sub Find_EnvironData()
    Dim i As Integer
    ActiveSheet.UsedRange.Clear
    For i = 1 To 38
    ActiveSheet.Cells(i, 1).Value = Environ(i)
    Next
    End Sub

    Retrieve Computer Name

     

  • In either way we can retrieve the output
  •  

    ?environ("COMPUTERNAME")
    PAVANKUMAR-PC
    ?environ(6)
    COMPUTERNAME=PAVANKUMAR-PC

     

    Download the workbook to find the environ elements

    Download The Workbook