VBA GetTempName

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 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