Last active
September 24, 2015 20:37
-
-
Save honda0510/805649 to your computer and use it in GitHub Desktop.
【VBA】文字エンコーディング変換関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 参照設定 | |
' 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