To get the path to the "TEMP" folder

grautu

New Member
Joined
Sep 26, 2004
Messages
38
Hi!
I would appreciate very much any piece of VBA code that turns the path to the "TEMP" environment variable. Any disparate VBA keyword is also appreciated.
Thanks in advance!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Environ function for accessing operating system environment variables

str_tmppath = Environ("temp")

Or may be another way, if you need to return Temporary System Folder, filesytem object's GetSpecialFolder method.

Function get_TempFolder()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
get_TempFolder = fso.GetSpecialFolder(2)
End Function

Suat
 
Upvote 0
Private Function BrowseForFolder(Title As String, Optional RootFolder As Variant) As String
'Standard module code, like: Module1!
Dim Shell As Object, Folder As Object

Set Shell = CreateObject("Shell.Application")
Set Folder = Shell.BrowseForFolder(0, Title, 0, RootFolder)

If (Not Folder Is Nothing) Then _
BrowseForFolder = Folder.ParentFolder.ParseName(Folder.Title).Path
End Function

Sub browzLocalPC()
'Standard module code, like: Module1!
Dim myPath As String

'*** User Option! ************************** Change "num" here for options! ***
myPath = BrowseForFolder("Please select your folder", 17)

'0 or missing=MS Win DesktopÂ-virtual folder that is the root of the namespace.
'2=File system directory, the user's program groups (also file system directories). Like: C:\Documents and Settings\username\Start Menu\Programs.
'3=Virtual folder icons for the Control Panel applications.
'4=Virtual folder installed printers.
'5=File system directory, for user's documents. Like: C:\Documents and Settings\username\My Documents.
'6=File system directory, for the user's favorite items. Like: C:\Documents and Settings\username\Favorites.
'7=File system directory, the Startup program group that starts on log to Win NT or Win 95. Like: C:\Documents and Settings\username\Start Menu\Programs\Startup.
'8=File system directory, the user's most recently used documents. Like: C:\Documents and Settings\username\Recent.
'9=File system directory, Send To menu items. Like: C:\Documents and Settings\username\SendTo.
'11=File system directory Start menu items. Like: C:\Documents and Settings\username\Start Menu.
'15=Virtual folder the objects in the user's Recycle Bin.
'16=File actual system directory used to store the file objects displayed the desktop. Not the desktop folder itself, A virtual folder. Like: C:\Documents and Settings\username\Desktop.
'17=My Computer, virtual folder for the local computer: storage devices, printers, and Control Panel, may also contain mapped network drives.
'18=Network Neighborhood, virtual folder representing the root of the network namespace hierarchy.
'19=A file system folder the link objects that may exist in the My Network Places virtual folder. Not the same as the network folders.
'20=Virtual folder installed fonts. Like: C:\WINNT\Fonts.
'21=File system directory for document templates.
'22=File system directory, the programs and folders the Start menu for users. Like: C:\Documents and Settings\All Users\Start Menu. Valid Win NT systems.
'23=File system directory, the directories for the program groups the Start menu for users. Like: C:\Documents and Settings\All Users\Start Menu\Programs. Valid Win NT systems.
'24=File system directory, the programs in the Startup folder for users. Like: C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid Win NT systems.
'25=File system directory, files and folders the desktop for all users. Like: C:\Documents and Settings\All Users\Desktop. Valid Win NT systems.
'26=File system directory current application data.
'27=File system directory, the link objects that may exist in the Printers virtual folder. Like: C:\Documents and Settings\username\PrintHood.
'28= Ver. 5.0. File system directory the data repository for local (non-roaming) applications. Like: C:\Documents and Settings\username\Local Settings\Application Data.
'29 = File system directory that corresponds to the user's nonlocalized Startup program group.
'30=File system directory that corresponds to the nonlocalized Startup program group for all users. Valid MS Win NT systems.
'31=File system directory for all users' favorite items. Valid Win NT systems.
'32=File system directory for temporary Internet files. Like: C:\Documents and Settings\username\Temporary Internet Files.
'33=File system directory for Internet cookies. Like: C:\Documents and Settings\username\Cookies.
'34=File system directory for Internet history items.
'35= Ver. 5.0. Application data for all users. Like: C:\Documents and Settings\All Users\Application Data.
'36= Ver. 5.0. Win directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. Like: C:\WINNT.
'37= Ver. 5.0. System folder. Like: C:\WINNT\SYSTEM32.
'38= Ver. 5.0. Program Files folder. Like: C:\Program Files.
'39=My Pictures folder. Like: C:\Documents and Settings\username\My Documents\My Pictures.
'40= Ver. 5.0. User's profile folder.


If myPath <> "" Then MsgBox myPath, vbInformation + vbOKOnly, "Your Selected Path!"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,521
Messages
6,120,018
Members
448,937
Latest member
BeerMan23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top