Các anh chị giúp em về lỗi compile khi thêm 1 hàm mới vào code của macro excel (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

truongh3t

Thành viên mới
Tham gia
20/10/12
Bài viết
3
Được thích
0
Em chào anh chị à. Em đang gặp 1 vấn đề như sau.
Em đang cần phải encoding trong file excel để có thể convert data từ Unicode sang UTF8
Tức là trong souce macro của excel.Em copy hàm sau vào.
Function UniStrToUTF8(UniString) As Byte()
' Convert a Unicode string to a byte stream of UTF-8
Dim BArray() As Byte
Dim TempB() As Byte
Dim i As Long
Dim k As Long
Dim TLen As Long
Dim b1 As Byte
Dim b2 As Byte
Dim UTF16 As Long
Dim j
TLen = Len(UniString) ' Obtain length of Unicode input string
If TLen = 0 Then Exit Function ' get out if there's nothing to convert
k = 0
For i = 1 To TLen
' Work out the UTF16 value of the Unicode character
CopyMemory b1, ByVal StrPtr(UniString) + ((i - 1) * 2), 1
CopyMemory b2, ByVal StrPtr(UniString) + ((i - 1) * 2) + 1, 1
' Combine the 2 bytes into the Unicode UTF-16
UTF16 = b2 ' assign b2 to UTF16 before multiplying by 256 to avoid overflow
UTF16 = UTF16 * 256 + b1
' Convert UTF-16 to 2 or 3 bytes of UTF-8
TempB = ToUTF8(UTF16)
' Copy the resultant bytes to BArray
For j = 0 To UBound(TempB)
ReDim Preserve BArray(k)
BArray(k) = TempB(j): k = k + 1
Next
ReDim TempB(0)
Next
UniStrToUTF8 = BArray ' Return the resultant UTF-8 byte array
End Function


Nhưng khi build code thì báo lỗi Function and Sub not defined .Nó báo lỗi ở hàm CopyMemory.
Khi rào thử đoạn code CopyMemory lại, thì compiled lỗi ở hàm ToUTF8
Em vẫn chưa biết nguyên nhân tại sao.Mong anh chị nào biết thì giúp đỡ em với à. Em xin cảm ơn anh chị
 
Web KT

Bài viết mới nhất

Back
Top Bottom