|
|
|
|
|
|
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()
If Application.VBE.MainWindow.Visible = False Then
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:
|
- Open an Excel Workbook
- Copy the code
- Press Alt + F11 to open the Visual Basic Editor (VBE)
- Select INSERT > MODULE from the menubar
- Paste code into the right pane
- Press Alt+Q to return to Excel
- Save workbook before any other changes
|
Test the code:
|
- Go to TOOLS > MACRO > MACROS
- When the dialog appears, select (GetEnvironVariables)
- Press Run
|
Sample File:
|
GetEnvironInfo.zip 7.21KB
|
Approved by mdmackillop
|
This entry has been viewed 223 times.
|
|