Answers for "excel vba save file txt"

VBA
0

excel vba save file txt

' Needs to add "Microsoft Scripting Runtime" reference to your file
Public Sub SaveTextToFile(ByVal pFile As String, ByVal pText As String)
    Dim fso As FileSystemObject
    Dim fileStream As TextStream

    Set fso = New FileSystemObject
    Set fileStream = fso.CreateTextFile(pFile)
    fileStream.WriteLine pText
    fileStream.Close
End Sub
' -----------------------------------------------------------------------
Sub TestMe()
      SaveTextToFile "C:\Temp\export.txt", "A sentence to be saved..."
End Sub
Posted by: Guest on January-31-2021

Code answers related to "VBA"

Browse Popular Code Answers by Language