IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Problème d'encodage du texte importé du net via excel [XL-2003]


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Problème d'encodage du texte importé du net via excel
    Bonjour tout le monde,
    Ma macro retraite des données importées d'internet via excel en utilisant données externes\à partir du site web et ensuite j'importe les données du site www.trivago.fr.

    Cela fonctionnait bien mais plus maintenant , le problème est que le texte est sous forme de caractères spéciaux , par exemple , au lieu d'avoir "Arrivée j'obtient Arrivée , ce qui fait bugguer ma macro

    Pouvez-vous svp m'aider à résoudre ce problème?
    Merci
    PJ : le texte importé
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent sénior
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Points : 11 272
    Points
    11 272
    Par défaut
    Salut, une recherche car pour le moment pas trouvé sur mon PC et je sais que j'ai qqch là dessus, donc en attendant.

    PS : J'ai retrouvé ceci, à placer dans un module standard pour pouvoir l'utiliser comme fonction personnalisée, sinon tu peux l'intégrer dans ton code VBA
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    Option Explicit
    
    Function Decode_UTF8(sStr As String) As String
    Dim c0 As Long, c1 As Long, c2 As Long, c3 As Long
    Dim n As Long
    Dim sTxt As String
    
        If isUTF8(sStr) = False Then
            Decode_UTF8 = sStr
            Exit Function
        End If
    
        sTxt = ""
        n = 1
        Do While n <= Len(sStr)
            c0 = Asc(Mid$(sStr, n, 1))
            If n <= Len(sStr) - 1 Then
                c1 = Asc(Mid$(sStr, n + 1, 1))
            Else
                c1 = 0
            End If
            If n <= Len(sStr) - 2 Then
                c2 = Asc(Mid$(sStr, n + 2, 1))
            Else
                c2 = 0
            End If
            If n <= Len(sStr) - 3 Then
                c3 = Asc(Mid$(sStr, n + 3, 1))
            Else
                c3 = 0
            End If
    
            If (c0 And 240) = 240 And (c1 And 128) = 128 And (c2 And 128) = 128 And (c3 And 128) = 128 Then
                sTxt = sTxt + ChrW((c0 - 240) * 65536 + (c1 - 128) * 4096) + (c2 - 128) * 64 + (c3 - 128)
                n = n + 4
            ElseIf (c0 And 224) = 224 And (c1 And 128) = 128 And (c2 And 128) = 128 Then
                sTxt = sTxt + ChrW((c0 - 224) * 4096 + (c1 - 128) * 64 + (c2 - 128))
                n = n + 3
            ElseIf (c0 And 192) = 192 And (c1 And 128) = 128 Then
                sTxt = sTxt + ChrW((c0 - 192) * 64 + (c1 - 128))
                n = n + 2
            ElseIf (c0 And 128) = 128 Then
                sTxt = sTxt + ChrW(c0 And 127)
                n = n + 1
            Else        ' c0 < 128
                sTxt = sTxt + ChrW(c0)
                n = n + 1
            End If
        Loop
    
        Decode_UTF8 = sTxt
    End Function
    
    Private Function isUTF8(sStr As String) As Boolean
    Dim c0 As Long, c1 As Long, c2 As Long, c3 As Long
    Dim n As Integer
    
        isUTF8 = True
        n = 1
        Do While n <= Len(sStr)
            c0 = Asc(Mid$(sStr, n, 1))
            If n <= Len(sStr) - 1 Then
                c1 = Asc(Mid$(sStr, n + 1, 1))
            Else
                c1 = 0
            End If
            If n <= Len(sStr) - 2 Then
                c2 = Asc(Mid$(sStr, n + 2, 1))
            Else
                c2 = 0
            End If
            If n <= Len(sStr) - 3 Then
                c3 = Asc(Mid$(sStr, n + 3, 1))
            Else
                c3 = 0
            End If
    
            If (c0 And 240) = 240 Then
                If (c1 And 128) = 128 And (c2 And 128) = 128 And (c3 And 128) = 128 Then
                    n = n + 4
                Else
                    isUTF8 = False
                    Exit Function
                End If
            ElseIf (c0 And 224) = 224 Then
                If (c1 And 128) = 128 And (c2 And 128) = 128 Then
                    n = n + 3
                Else
                    isUTF8 = False
                    Exit Function
                End If
            ElseIf (c0 And 192) = 192 Then
                If (c1 And 128) = 128 Then
                    n = n + 2
                Else
                    isUTF8 = False
                    Exit Function
                End If
            ElseIf (c0 And 128) = 0 Then
                n = n + 1
            Else
                isUTF8 = False
                Exit Function
            End If
        Loop
    End Function

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2012
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Merci et désolé pour ce retard

    mon fichier fonctionne normalement maintenant ,comme auparavant
    j'aimerai bien comprendre d'ou vient le problème

  4. #4
    Expert éminent sénior
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Points : 11 272
    Points
    11 272
    Par défaut
    Salut, n'ayant pas de boule de cristal à disposition ..... Le problème semblant récurrent tu peux utiliser systématiquement la solution proposée.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'encodage dans l'importation d'un .csv
    Par Sayanel01 dans le forum Général VBA
    Réponses: 2
    Dernier message: 30/04/2015, 23h17
  2. Problème de parcours et de tri pour outlook via Excel
    Par Shamix dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/11/2013, 11h19
  3. Importation de données via excel
    Par Jynno22 dans le forum Excel
    Réponses: 0
    Dernier message: 26/01/2013, 20h17
  4. Problème d'encodage de texte
    Par cecile38 dans le forum Développement Web en Java
    Réponses: 6
    Dernier message: 13/01/2012, 10h50
  5. Problème d'encodage de texte
    Par Grantoumaigr dans le forum VB.NET
    Réponses: 2
    Dernier message: 28/09/2007, 16h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo