Function StringToFile(strString As String, strFile As String) As Boolean
' Purpose:
' Write a string to a file. The file is opened in binary mode, so
' the string content is written exactly as is.
' Input:
' strString - The string to write
' strFile - Fully qualified name of the file to create
' Output:
' True or False indicating the success of the write operation
' Remarks:
' If the strFile does not exist it is created. If it exists, the
' existing copy is overwritten without any warning.
Dim h As Integer
h = FreeFile
Open strFile For Binary Access Write Lock Write As #h
Put #h, , strString
Close #h
StringToFile = True
StringToFile_Exit:
Exit Function
StringToFile_Error:
StringToFile = False
Resume StringToFile_Exit
End Function
Private Sub Command1_Click()
'Text1 is the text that will be saved, Text2 well be the name and path to the file
StringToFile Text1, Text2
'Clear form
Text1 = ""
Text2 = ""
MsgBox "Data has been Save to a text file."
End Sub