2018-04-16

[VBA] Read Write UTF-8 File

Dim reader As Object
Set reader = CreateObject("ADODB.Stream")
reader.CharSet = "UTF-8"
reader.LineSeparator = 10
reader.Open
reader.LoadFromFile "C:\test.txt"

Dim textLine As String
Do Until reader.EOS
    textLine = reader.ReadText(-2)
Loop
reader.Close


Dim writer As Object
Set writer = CreateObject("ADODB.Stream")
writer.CharSet = "UTF-8"
writer.Open
writer.WriteText "xxxxxxx" & Chr(10)

writer.SaveToFile "C:\test.txt", 2
writer.Close

1 則留言:

你好!歡迎你在我的 Blog 上留下你寶貴的意見。