VB and VBA Users Source Code: Create a name for a temporary file
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Create a name for a temporary file
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, March 21, 2001
Hits:
878
Category:
Windows API
Article:
The following function creates a name for a temporary file which can be used to store temporary data. 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 Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long 'Purpose : The FileGetTempName function returns a name of a temporary file. 'Inputs : [sFilePrefix] The prefix of the file name. 'Outputs : Returns the name of the next free temporary file name (and path). 'Author : Andrew Baker 'Date : 03/09/2000 14:17 'Notes : The filename is the concatenation of specified path and prefix strings, ' a hexadecimal string formed from a specified integer, and the .TMP extension 'Revisions : Function FileGetTempName(Optional sFilePrefix As String = "TMP") As String Dim sTemp As String * 260, lngLen As Long Static ssTempPath As String If LenB(ssTempPath) = 0 Then 'Get the temporary path lngLen = GetTempPath(260, sTemp) 'strip the rest of the buffer ssTempPath = Left$(sTemp, lngLen) If Right$(ssTempPath, 1) <> "\" Then ssTempPath = ssTempPath & "\" End If End If 'Get a temporary filename lngLen = GetTempFileName(ssTempPath, sFilePrefix, 0, sTemp) 'Remove all the unnecessary chr$(0)'s FileGetTempName = Left$(sTemp, InStr(1, sTemp, Chr$(0)) - 1) End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder