Discover The Temp Folder Path
May 26, 2021 - by Bill Jelen
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:
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:
When you run this code, you get a listing similar to the one shown in Figure 131.
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:
Some common environment variables that appear on most systems include:
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:
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.