这是一个转文本为UTF-8文件的例子。在另一个帖子里说过的。 Public Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long Public Const CP_UTF8 = 65001 Sub writetoUTF8() Dim strstr As String Dim bByte As Byte Dim lBufSize As Long Dim lRest As Long Dim bUTF8() As Byte Dim TLen As Long strstr = "大家好,这里是转换Unicode和UTF-8的代码." TLen = Len(strstr) lBufSize = TLen * 3 + 1 ReDim bUTF8(lBufSize - 1) lRest = WideCharToMultiByte(CP_UTF8, 0, StrPtr(strstr), TLen, bUTF8(0), lBufSize, vbNullString, 0) If lRest Then lRest = lRest - 1 ReDim Preserve bUTF8(lRest) Open "c:\xfwen\excelhelp\UTF8try.txt" For Binary As #1 bByte = 239 Put #1, , bByte bByte = 187 Put #1, , bByte bByte = 191 Put #1, , bByte Put #1, , bUTF8 Close #1 End If End Sub |