Private Declare Function GetTempPath Lib "kernel32" Alias _
"GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Public Function GetNewTempFile(strPrefix As String) As String' strPrefix can be whatever you want Dim strPath As String * 512
Dim strName As String * 576
Dim lngRetVal As Long
lngRetVal = GetTempPath(512, strPath)
If (lngRetVal > 0 And lngRetVal < 512) Then
lngRetVal = GetTempFileName(strPath, strPrefix, 0, strName)
If lngRetVal <> 0 Then
GetNewTempFile = Left$(strName, _
InStr(strName, vbNullChar) - 1)
End If
End If
End Function