Skip to content

Instantly share code, notes, and snippets.

@mattcan
Last active December 11, 2015 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcan/4658068 to your computer and use it in GitHub Desktop.
Save mattcan/4658068 to your computer and use it in GitHub Desktop.
I always forget how to create a new text file so I put together this factory. You will need to reference the Microsoft Scripting Runtime library in your VBA project.
' Make sure you've referenced the Microsoft Scripting Runtime library in your project
' In the VBA Editor: Tools > References...
Function TextStreamFactory(ByVal NewFileName As String) As Scripting.TextStream
Dim fs As New Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Set ts = fs.CreateTextFile(NewFileName)
Set TextStreamFactory = ts
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment