CHRIS RAE'S VBA PAGES

Routine Archive


Module:GetTempPath
Description:Find the temporary file path used by Windows.

' Written by Mark D'Elton, Australia(markd@net2000.com.au).

Option Explicit

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
                (ByVal nBufferLength As Long, _
                ByVal lpBuffer As String) As Long
Public Function GetTempDir() As String
    Dim sBuffer As String
    Dim lRetVal As Long

    sBuffer = String(255, vbNullChar)

    lRetVal = GetTempPath(Len(sBuffer), sBuffer)

    If lRetVal Then
        GetTempDir = Left$(sBuffer, lRetVal)
    End If
End Function

You're free to use these routines for anything you want - all I ask is that for commercial use you give me credit somewhere. You may instead want to head back to the index for my Visual Basic for Applications Pages or the main routines archive page.