Excel VBA Access Environment Variables

Josh Hazel
05-05-2010, 02:34 PM
I am wondering if using VBA code I would be able to access "Environment Variables" and their values.

I assume the advanced users here know what I am speaking of, if not you can find these by right clicking on My Computer / Properties / Advanced / Environment Variables

Lets say there is a variable titled TEMP and the value is c:\documents and settings\testfolder, i would like to retrieve the value (that string)

Colin Legg
05-05-2010, 03:45 PM
Try:

Debug.Print VBA.Environ$("TEMP")

Josh Hazel
05-05-2010, 08:24 PM
Works perfectly, thanks! I will have to seek out a good website re Environ, ive pulled windows username from login with it before, seems like it may have more useful applications

Colin Legg
05-06-2010, 02:00 AM
I don't know if you'll find a good website on it, but you can see the string arguments available on your PC if you run a test loop:

Sub foo()
Dim i As Long

For i = 1 To 80
Debug.Print VBA.Environ(i)
Next i

End Sub

The first part of the immediate window output on each line (before the = sign) is the string argument you can pass into the function.

Bob Phillips
05-06-2010, 05:02 AM
And ... you can create your own.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum