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

Excel Discussion :

Macro VBA: "Désolé Nous avons trouvé un problème dans le contenu de"


Sujet :

Excel

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2015
    Messages : 7
    Points : 7
    Points
    7
    Par défaut Macro VBA: "Désolé Nous avons trouvé un problème dans le contenu de"
    Bonjour à tous,
    Il m'arrive un problème depuis quelques jours avec mes classeurs excel (prenant en charge les macros). J'arrive habituellement a me dépatouiller tout seul en faisant des recherches, notamment dans ce forum. Mais là je sèche, je me suis donc spécialement inscrit sur ce forum pour demander votre aide!

    Voici mon problème, depuis peu ce message s'affiche a l'ouverture de certains de mes classeurs excel:

    "Désolé... Nous avons trouvé un problème dans le contenu de [Nom Fichier], mais nous pouvons récupérer le maximum de contenu. Si la source de ce classeur est fiable, cliquez sur Oui."

    J'ai quelques informations supplémentaires a vous apporter:
    - Ce message d'erreur s'affiche sur TOUT les excel que j'ai essayer sur plusieurs machine, cela ne vient donc pas de l'installation d'excel ou de l'ordinateur!
    - Une fois que je clique sur "oui", le classeur s'ouvre normalement, les données sont inchangées et tout fonctionne normalement, du moins à première vue
    - Le problème vient des tri que j'effectue en VBA sur les différentes feuilles de mon classeur
    - Ce message est survenu (je pense) a l'ajout d'un code, sensé s’exécuter a l'ouverture du classeur (mais le message d'erreur survient avant!):


    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
    Private Sub Workbook_Open()
     
     
     
     
    'tri des données sur année mois
     
    On Error Resume Next
    ActiveWorkbook.Worksheets("Sexe").ShowAllData
    On Error GoTo 0
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sexe").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    On Error Resume Next
    ActiveWorkbook.Worksheets("Age").ShowAllData
    On Error GoTo 0
    ActiveWorkbook.Worksheets("Age").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Age").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Age").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Age").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
    End sub

    Je suis nouveau ici et j'espère respecter les règles du forums comme il faut, je suis dans une belle impasse avec cette erreur incompréhensible, toutes les réponses sont les bienvenues! Merci d'avance!

    PS: Le message n’apparaît pas systématiquement à chaque ouverture

  2. #2
    Expert éminent sénior Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Points : 32 866
    Points
    32 866
    Par défaut
    Première chose à faire : mettre en commentaire toutes les lignes contenant un "On Error" qui ne servent qu'à empêcher de voir où et quand se produit l'erreur.

    Est-ce qu'il y a d'autres macros dans ton fichier ?

    Citation Envoyé par Pataproot Voir le message
    Je suis nouveau ici et j'espère respecter les règles du forums comme il faut
    Les questions VBA doivent être posées dans la sous-rubrique VBA d'Excel.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2015
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    Tout d'abord un grand merci pour cette réponse très rapide!

    J'ai mis tout les "on error" en commentaire, j'envoie le code complet de cette macro:

    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
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    Private Sub Workbook_Open()
     
     
     
     
    'tri des données sur année mois
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Sexe").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sexe").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Age").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Age").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Age").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Age").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Age").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Canaux").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Canaux").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Canaux").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Canaux").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Canaux").Sort
            .SetRange Range("A:L")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Centre d'interêt").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Centre d'interêt").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Centre d'interêt").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Centre d'interêt").Sort.SortFields.Add Key:=Range("B:B") _
           , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Centre d'interêt").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Requêtes").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Requêtes").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Requêtes").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Requêtes").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Requêtes").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Résultats").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Résultats").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Résultats").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Résultats").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Résultats").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Page d'attérissage").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Page d'attérissage").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Page d'attérissage").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Page d'attérissage").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Page d'attérissage").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Page de sortie").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Page de sortie").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Page de sortie").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Page de sortie").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Page de sortie").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Comportement").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Comportement").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Comportement").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Comportement").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Comportement").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
    'On Error Resume Next
    ActiveWorkbook.Worksheets("Appareils").ShowAllData
    'On Error GoTo 0
    ActiveWorkbook.Worksheets("Appareils").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Appareils").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Appareils").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Appareils").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
     
     
    End Sub

    Une erreur survient alors, mais uniquement pour la feuille "Centre d'intérêt": "La méthode ShowAllData de la classe worksheet à échoué". Il me semble que c'est parce qu'il n'y a pas de filtre actif sur cette feuille du classeur, d'ou les "On error", je vais donc mettre en commentaire les "ShowAllData" également et voir si le message d'erreur à l'ouverture persiste!
    EDIT: Même sans les "ShowAllData" et donc les "On error", le message continue d'apparaître à l'ouverture! Je me demande donc si le problème ne viendrait pas du fait que je tri certaine feuille qui non pas de données?

    Est-ce qu'il y a d'autres macros dans ton fichier ?
    Il y a d'autres macro que j'ai réalisé afin de mettre en place un tableau de bord dynamique en fonction des données de mes différentes feuilles!

    Les questions VBA doivent être posées dans la sous-rubrique VBA d'Excel.
    Dois-je déplacer mon topic?

    Merci encore!

  4. #4
    Expert éminent sénior Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Points : 32 866
    Points
    32 866
    Par défaut
    Citation Envoyé par Pataproot Voir le message
    Une erreur survient alors, mais uniquement pour la feuille "Centre d'intérêt": "La méthode ShowAllData de la classe worksheet à échoué".
    C'est déjà plus explicite.

    Il me semble que c'est parce qu'il n'y a pas de filtre actif sur cette feuille du classeur, d'ou les "On error",
    Il vaut mieux comprendre l'erreur et modifier le code que la masquer avec des On Error.

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2015
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    Je crois avoir résolu le problème, le tri d'une feuille sans donnée provoquait le message d'erreur il me semble!

    Un extrait du code permettant d'éviter cela, pour les personnes ayant le même problème:
    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
     
    If ActiveWorkbook.Worksheets("Sexe").Range("A2") = "" Then
    Else
     
    ActiveWorkbook.Worksheets("Sexe").ShowAllData
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Add Key:=Range("A:A") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sexe").Sort.SortFields.Add Key:=Range("B:B") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
            "janvier,février,mars,avril,mai,juin,juillet,août,septembre,octobre,novembre,décembre", DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sexe").Sort
            .SetRange Range("A:Z")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
    End With
    End If
    Je ne suis pas encore sur que message d'erreur à l'ouverture venait de là, car comme je l'ai préciser, le message ne survenait pas à chaque ouverture! Mais après plusieurs test cela à l'air concluant, je met le topic en résolu, je testerais plus tard sur d'autre excel/machine, si tout va bien le topic restera comme tel.

    Sinon Merci Menhir pour tes réponses!

    A bientôt!

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

Discussions similaires

  1. Connaître la taille d'un module avec une macro VBA ou autre
    Par beegees dans le forum Général VBA
    Réponses: 15
    Dernier message: 22/11/2005, 09h47
  2. probleme de selection aleatoire sur excel avec macro vba
    Par guillaume sors dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 21/10/2005, 10h51
  3. Macro VBA sur Access
    Par beurnoir dans le forum Access
    Réponses: 3
    Dernier message: 12/10/2005, 16h46
  4. [SQL][MACRO VBA]Pb de syntaxe
    Par Stef.proxi dans le forum Langage SQL
    Réponses: 2
    Dernier message: 11/08/2004, 09h11

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