Skip to content

Instantly share code, notes, and snippets.

@honda0510

honda0510/gist:805649

Last active Sep 24, 2015
Embed
What would you like to do?
【VBA】文字エンコーディング変換関数
' 参照設定
' Microsoft ActiveX Data Objects 2.x Library
Function ConvCharSet(from_bin, from_charset, to_charset)
Dim from_stm As ADODB.Stream
Dim to_stm As ADODB.Stream
' バイナリ型のStreamオブジェクトを作成
Set from_stm = New ADODB.Stream
from_stm.Open
from_stm.Type = adTypeBinary
from_stm.Write from_bin
from_stm.Position = 0
from_stm.Type = adTypeText
from_stm.Charset = from_charset
' テキスト型のStreamオブジェクトを作成
Set to_stm = New ADODB.Stream
to_stm.Open
to_stm.Type = adTypeText
to_stm.Charset = to_charset
' to_charsetに変換されてコピーされる
from_stm.CopyTo to_stm
to_stm.Position = 0
to_stm.Type = adTypeBinary
If to_charset = "UTF-8" Then
to_stm.Position = 3
End If
' 文字コード変換後のバイナリを返す
ConvCharSet = to_stm.Read
from_stm.Close
to_stm.Close
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.