Excel VBA: Open UTF-16 XML

Je suis actuellement en train d'ouvrir un file XML encodé utf-16 avec VBA dans Excel.

Ma variable Ssortingng actuelle intitulée EntireFile commence actuellement comme ceci:

ÿþ<?xml version="1.0" encoding="utf-16"?> <Test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

Comme vous pouvez le voir, certains personnages commencent au début.

J'obtiens la variable Ssortingng en effectuant:

 Open PathToFile For Input As #1 Do Until EOF(1) Line Input #1, textline EntireFile = EntireFile & textline 

Marco ddeaeaeaeaeaeaeaeaeaaneaFeaeaFeaeaFneacheaeaeadiceTeaeaeaAFeaMeaeaeaeaFeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaeaea1diceeaeaeadicediceHeafeeaeaeaeaAeaeaeaeaCAeaeaeaeaeaeaeaeaeaeaeaagdicedicediceAeaeaeaeaea Daeaeaea Daeaeaea Da MarcoFeaeaeaea Dafeeaea Daea Da Marco Daea Da Marco citadeaeaea Dafeidence Dafeidence Dafeea Daea Da Marco Traea citea Da

J'ai essayé la méthode bruteforce de supprimer les deux premiers caractères mais cela me laisse avec une string vide.

Tous les résultats de google couvrent l'logging d'un file XML sans la nomenclature, mais c'est plutôt l'opposé de ce que je search.

Merci déjà pour votre time

    Vous pouvez utiliser les fonctions de l'API Win32 pour convertir les enencodings.

     Private Declare Function WideCharToMultiByte Lib "kernel32.dll" ( _ ByVal CodePage As Long, _ ByVal dwFlags As Long, _ ByVal lpWideCharStr As Long, _ ByVal cchWideChar As Long, _ ByVal lpMultiByteStr As Long, _ ByVal cbMultiByte As Long, _ ByVal lpDefaultChar As Long, _ ByVal lpUsedDefaultChar As Long) As Long Private Declare Function MultiByteToWideChar Lib "kernel32.dll" ( _ ByVal CodePage As Long, _ ByVal dwFlags As Long, _ ByVal lpMultiByteStr As Long, _ ByVal cbMultiByte As Long, _ ByVal lpWideCharStr As Long, _ ByVal cchWideChar As Long) As Long Private Const CP_UTF16 As Long = 1200& Private Function ConvertToUTF16(ByRef Source As Ssortingng) As Byte() Dim Length As Long Dim Pointer As Long Dim Size As Long Dim Buffer() As Byte Length = Len(Source) Pointer = StrPtr(Source) Size = WideCharToMultiByte(CP_UTF16, 0, Pointer, Length, 0, 0, 0, 0) ReDim Buffer(0 To Size - 1) WideCharToMultiByte CP_UTF16, 0, Pointer, Length, VarPtr(Buffer(0)), _ Size, 0, 0 ConvertToUTF16 = Buffer End Function Private Function ConvertFromUTF16(ByRef Source() As Byte) As Ssortingng Dim Size As Long Dim Pointer As Long Dim Length As Long Dim Buffer As Ssortingng Size = UBound(Source) - LBound(Source) + 1 Pointer = VarPtr(Source(LBound(Source))) Length = MultiByteToWideChar(CP_UTF16, 0, Pointer, Size, 0, 0) Buffer = Space$(Length) MultiByteToWideChar CP_UTF16, 0, Pointer, Size, StrPtr(Buffer), Length ConvertFromUTF16 = Buffer End Function 

    Private Const CP_UTF16 As Long = 1200& signifie codepage 1200 qui est UTF-16 little andian.

    Vous pouvez voir une list de toutes les pages de code ici https://msdn.microsoft.com/default.aspx /