Uses Kernel32 to retrieve the path for the Windows temporary directory.
Module
Private Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String _
) As Long
Public Function GetTempDir() As String
' Returns the temp directory from the OS system
Dim sBuffer As String
Dim HoldBuffer As String
Dim iBuffLen As Long
Dim iReturn As Long
Const BUFFER_LENGTH = 256
iBuffLen = BUFFER_LENGTH
sBuffer = Space(BUFFER_LENGTH)
iReturn = GetTempPath(iBuffLen, sBuffer) '* get rid of the null character
HoldBuffer = Left$(sBuffer, iBuffLen - 1)
GetTempDir = Left$(HoldBuffer, InStr(HoldBuffer, vbNullChar) - 1)
End Function
Usage
Private Sub Command1_Click()
MsgBox GetTempDir
End Sub