2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【VBA】UTF-8のファイルを1行ずつ読み取る。

Posted at

メモとして残します。

■やり方

filepath = "D:\import.txt"
With CreateObject("ADODB.Stream")
    .Open
    .Charset = "UTF-8"'BOMあり、BOMなし両対応
    .LineSeparator = -1 '-1=CRLF
    .LoadFromFile filepath
    
    '1行毎に処理
    Do Until .EOS
        TextLine = .ReadText(-2)'1行取り出す
        '処理・・・・
    Loop
    .Close
End With

■さいごに

ADODB.Streamは書き込みの際はBOM無し処理は少しだけ面倒ですが、今回の読み取りの場合BOM有り、BOM無しにかかわらず、これで問題なさそうでしたが、環境にもよりそうなので、一応BOM無しの場合は注意。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?