LoginSignup
5
5

More than 5 years have passed since last update.

VBAでUTF-8のテキストを読み込む

Last updated at Posted at 2013-11-25
Public Function ReadUTF8Text(isFilePath As String) As String

    'オブジェクトを作る
    Dim objStream As Object
    Set objStream = CreateObject("ADODB.Stream")

    '読み込むテキストのタイプを設定する
    '指定できるタイプはadTypeBinary(バイナリ)とadTypeText(テキスト)
    objStream.Type = adTypeText

    '文字コードをUTF-8に設定する
    '指定できる文字コードはHKEY_CLASSES_ROOT\MIME\Database\Charsetのサブキー
    objStream.Charset = "UTF-8"

    'ストリームを開く
    objStream.Open

    'ファイルを読み込む
    objStream.LoadFromFile(isFilePath)

    'テキスト内容を返却する
    ReadUTF8Text = objStream.ReadText

    'ストリームを閉じる
    objStream.Close

    Set objStream = Nothing

End Function
5
5
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
5
5