VBA 输出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 Private Sub WriteOut(strPath As String, str As String) Dim lBufSize As Long Dim lRest As Long Dim bUTF8() As Byte Dim TLen As Long TLen = Len(str) lBufSize = TLen * 3 + 1 ReDim bUTF8(lBufSize - 1) lRest = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), TLen, bUTF8(0), lBufSize, vbNullString, 0) If lRest Then lRest = lRest - 1 ReDim Preserve bUTF8(lRest) Open strPath For Binary As #1 Put #1, , bUTF8 Close #1 End If End Sub

你可能感兴趣的:(VBA 输出utf-8格式文件)