Excel

List Environ info

Ease of Use

Easy

Version tested with

2000, 2002, 2003 

Submitted by:

Justinlabenne

Description:

Returns all the Strings associated with an operating systems environment variables 

Discussion:

This code is useful if you need to obtain info about your users operating system. The code loops through all the Environment variables available, and returns the name of the variable, and the string value associated with it. The Environ function is used to obtain things like the Windows Username, Userprofile, System root, etc... after running the code you will see the resulting list in the vbe's Immediate Window. 

Code:

instructions for use

			

Option Explicit Sub GetEnvironVariables() ' --------------------------------------------------------- ' List all the available Environ information ' Environ Function returns info about the operating system ' Info will be listed in the Immediate Window (Ctrl+G) ' --------------------------------------------------------- If Application.VBE.MainWindow.Visible = False Then ' --------------------------------------------------------- ' To ensure you see the result, I used SendKeys to open ' the vbe, and then display the Immediate Window SendKeys "%{F11}", True SendKeys "^g", True GoTo RunProc ' --------------------------------------------------------- Else RunProc: Dim i As Integer i = 1 While Environ(i) <> Empty Debug.Print Environ(i) i = i + 1 Wend End If End Sub

How to use:

  1. Open an Excel Workbook
  2. Copy the code
  3. Press Alt + F11 to open the Visual Basic Editor (VBE)
  4. Select INSERT > MODULE from the menubar
  5. Paste code into the right pane
  6. Press Alt+Q to return to Excel
  7. Save workbook before any other changes
 

Test the code:

  1. Go to TOOLS > MACRO > MACROS
  2. When the dialog appears, select (GetEnvironVariables)
  3. Press Run
 

Sample File:

GetEnvironInfo.zip 7.21KB 

Approved by mdmackillop


This entry has been viewed 223 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express