The FileSystemObject VBA GetTempName function returns a randomly generated available file path for a temporary file. No file is generated in this process however this is useful if temporary files need to be created quickly.
VBA FileSystemObject Methods
- BuildPath
- CopyFile
- CopyFolder
- CreateFolder
- CreateTextFile
- DeleteFile
- DeleteFolder
- DriveExists
- FileExists
- FolderExists
- GetAbsolutePathName
- GetBaseName
- GetDrive
- GetDriveName
- GetExtensionName
- GetFile
- GetFileName
- GetFolder
- GetParentFolderName
- GetSpecialFolder
- GetTempName
- MoveFile
- MoveFolder
- OpenTextFile
VBA GetTempName Syntax
fso.GetTempName
VBA GetTempName Examples
The function is usually used to create temporary files e.g. using the VBA CreateTextFile method:
Set fso = CreateObject("Scripting.FileSystemObject") Dim tempFileName as String tempFileName = fso.GetTempName() 'Result: "rad65800.tmp" 'Now you can create a text file in the current directory and write Set ts = fso.CreateTextFile(tempFileName) ts.WriteLine "Hello" ts.Close