Discover The Temp Folder Path


May 26, 2021 - by Bill Jelen

Discover The Temp Folder Path

Challenge: I want to find the path to my computer’s temp folder in VBA. 

Solution: To discover the path to your computer’s temp folder, use this code:

e9781615474011_i0240.jpg

The Environ function provides a remarkable amount of information about a system. However, you should be careful because the variables available on one computer may not be available on another computer.

To discover which variables are available on your system, use this code:

e9781615474011_i0241.jpg

When you run this code, you get a listing similar to the one shown in Figure 131.

Figure 131. A list of environment variables and their values for one particular system.
Figure 131. A list of environment variables and their values for one particular system.

Each entry in the list contains the environment variable name, an equals sign, and the value on that computer. When you know what variable names are available, you can pass the variable name in quotes:

e9781615474011_i0243.jpg

Some common environment variables that appear on most systems include:

e9781615474011_i0244.jpg

Additional Details: The Environ function does not work in the Excel grid. You can build a user-defined function to make it available to the Excel interface. To do so, use this code:

e9781615474011_i0245.jpg

You can then use =myenviron(“COMPUTERNAME”) in a cell in Excel.

Summary: On a Windows PC, the VBA Environ function provides information about the path to the temp folder, the path to the application data folder, and more.

Source: To get the path to the "TEMP" folder on the MrExcel Message Board.

Title Photo: Lili Popper on Unsplash


This article is an excerpt from Excel Gurus Gone Wild.



Bill Jelen is the author / co-author of:
Excel Dynamic Arrays Straight to the Point 2nd Edition

Fifteen months after Dynamic Arrays debuted for Office Insiders, the functions are being released to General Availability. This second edition of the book has been updated with new examples: see how Dynamic Arrays make XLOOKUP better. The chapter on the logic behind arrays has been expanded.