chat1
Sub AppendStringToFile(cleanedString As String)
Dim fileNum As Integer
Dim sanitizedString As String
Dim filename As String
' Hard-coded filename
filename = "C:\path\to\your\file.txt" ' Replace with your desired file path
' Remove newlines (vbCr, vbLf, vbCrLf) from the input string
sanitizedString = Replace(cleanedString, vbCrLf, "")
sanitizedString = Replace(sanitizedString, vbCr, "")
sanitizedString = Replace(sanitizedString, vbLf, "")
' Get a free file number
fileNum = FreeFile
' Open the file for appending
Open filename For Append As #fileNum
' Write the sanitized string to the file, followed by a newline
Print #fileNum, sanitizedString
' Close the file
Close #fileNum
End Sub