excel vba write string to text file vba write text file

The solution for “excel vba write string to text file vba write text file” can be found here. The following code will assist you in solving the problem.

‘VBA function to write string to text file:

Function SaveStringAsTextFile$(s$, fName$)
Const adSaveCreateOverWrite = 2
With CreateObject(“ADODB.Stream”)
.Charset = “utf-8”
.Open
.WriteText s
.SaveToFile fName, adSaveCreateOverWrite
End With
End FunctionOpen ThisWorkbook.Path & “\log.txt” For Append As #1
Write #1, “Here is my text.”
Write #1, “Another line.”
Close #1

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

Similar Posts