Friday, March 12, 2010

Fetch Temp directory of Windows using VBA macros

Hey,
I am working on VBA Macros for a small module.I came across a need to find the temp directory path using VBA.so here it is:

Public Function GetTempDir() As String
Dim sRet As String, lngLen As Long
'create buffer
sRet = String(MAX_PATH, 0)

lngLen = GetTempPath(MAX_PATH, sRet)
If lngLen = 0 Then Err.Raise Err.LastDllError
GetTempDir = Left$(sRet, lngLen)
End Function



Access above function here as :
Sub TestMacro

Dim strFilePath As String
strFilePath = GetTempDir()
End Sub

Regards,
Nitin Sharma