|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
以前的一个代码,不写BOM文件头,就是你要求的结果了。
Public Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar 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 |
|