excel vba write text file code example
Example 1: excel vba 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 Function
Example 2: excel vba open text file
Function OpenTextFile$(f)
With CreateObject("ADODB.Stream")
.Charset = "utf-8"
.Open
.LoadFromFile f
OpenTextFile = .ReadText
End With
End Function
s = OpenTextFile("C:\123.json")
MsgBox Len(s)