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 :

Code simple qui plante sous vista et non sous XP ou W7


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 9
    Par défaut Code simple qui plante sous vista et non sous XP ou W7
    Bonjour,
    je suis fasse à un problème très étrange, j'ai un fichier excel avec prise en charge des macro (.xlms) qui marche correctement sur les configurations suivantes:

    excel 2003 + windows xp
    excel 2007 + windows xp
    excel 2007 + windows seven

    Et elle ne marche pas sur le poste d'un client
    excel 2007 + windows vista

    Lorsque je lance ma macro, j'intercepte une erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Set newSheet2 = Sheets.Add
        newSheet2.Name = "Calcul2"
        On Error GoTo Err1:
    Err1:
        If Err <> 0 Then
        MsgBox "erreur de formatage"
        End If
    J'ai cette erreur que sur Vista

    j'ai regardé du coté des options régionales et linguistiques, de l'option L1C1 ou des droits sur les macros (le fichier est protégé).
    Mais rien n'y fait j'ai les même paramètres.

    Une idée ?

    Merci par avance

  2. #2
    Expert confirmé
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    4 122
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 4 122
    Par défaut
    Salut
    Ta gestion d'erreur est un peu bizarre je trouve.
    Quel numéro d'erreur te retourne ton code?

    Tu es bien sur que l'erreur vient de la création de ton onglet supplémentaire? A mon avis, ton code génère une erreur ailleurs et tu la retrouves en fin de code
    Fais voir un extrait un peu plus complet de ton code Stp

    ++
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2009
    Messages : 9
    Par défaut
    J'ai renvoyé le document sans ma gestion d'erreur qui n'était pas bonne. J'en serais plus sur mon erreur, mais de mémoire c'était une erreur
    "impossible de renommer une feuille".

    Je sais pas si le code est très utile, la macro est grosse (3k lignes), et le code n'est pas de moi et difficilement maintenable.
    Ma grande question est pourquoi ça marche sur mon excel et pas le leur. Est ce qu'un paramètre dans les options empêcherait ma macro de fonctionner correctement ?

    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
    ActiveWorkbook.Protect Structure:=False
     
        Set newSheet2 = Sheets.Add
        newSheet2.Name = "Calcul2"
     
        ActiveWorkbook.Protect Structure:=True
        'boucle ingénieur
        heure_totale = 0
        Call hypothese(debut_hyp, "ING")
        heure_totale_ing = heure_totale
     
        'boucle at
        heure_totale = 0
        Call hypothese(hypothese_stop, "AT")
        heure_totale_at = heure_totale
     
        'boucle stag
        heure_totale = 0
        Call hypothese(hypothese_stop, "Stagiaire")
         heure_totale_stag = heure_totale
        Cells(hypothese_stop + 1, 4).FormulaR1C1 = "=sum(R[" & (debut_hyp - hypothese_stop - 1) & "]C[0]:R[-1]C[0])"
     
        newSheet2.Activate
        ActiveWorkbook.Protect Structure:=False
        Application.DisplayAlerts = False
        Worksheets(newSheet2.Name).Delete
        Application.DisplayAlerts = True
        ActiveWorkbook.Protect Structure:=True
     
     
       'hypothèse sous traitance
     
        Cells(hypothese_stop + 3, 1).Value = "Hypothèses effectif sous traitant:"
        debut_hyp_sst = hypothese_stop + 3
     
        'titre colonne
        Cells(debut_hyp_sst + 1, 2).Value = "Nb h travaillées"
        Cells(debut_hyp_sst + 1, 2).Select
        Selection.Interior.ColorIndex = 42
            With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
            End With
            With Selection.Font
            .Name = "Arial"
            .FontStyle = "Gras"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
            End With
     
        'Copie sous traitance
        heure_totale = 0
        f = 2
        Do
            vide = IsEmpty(Worksheets("Parametres").Cells(f, 7))
            f = f + 1
        Loop While vide = 0
        cellulevide = f - 2
     
        For f = 2 To cellulevide
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 1).Value = Worksheets("Parametres").Cells(f, 7)
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 1).Interior.ColorIndex = 42
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 2).Value = Worksheets("Parametres").Cells(f, 8)
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 2).HorizontalAlignment = xlCenter
        heure_totale = Worksheets("Parametres").Cells(f, 8) + heure_totale
        Next
        heure_totale_sst = heure_totale
     
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 1).Value = "Total"
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 1).Interior.ColorIndex = 42
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 2).Value = heure_totale_sst
        Worksheets("Prevision").Cells(debut_hyp_sst + f, 2).HorizontalAlignment = xlCenter
        fin_sst = debut_hyp_sst + f
     
     
     
     
     
     
     
        'calcul heures potentielles
        Cells(debut_potentiel, 2).Value = heure_totale_ing
        Cells(debut_potentiel, 2).HorizontalAlignment = xlCenter
        Cells(debut_potentiel, 3).Value = heure_totale_at
         Cells(debut_potentiel, 3).HorizontalAlignment = xlCenter
        Cells(debut_potentiel, 4).Value = heure_totale_stag
         Cells(debut_potentiel, 4).HorizontalAlignment = xlCenter
        Cells(debut_potentiel + 1, 2).FormulaR1C1 = "=R[-4]C[0]-R[-1]C[0]"
        Cells(debut_potentiel + 1, 2).HorizontalAlignment = xlCenter
        Cells(debut_potentiel + 1, 3).FormulaR1C1 = "=R[-4]C[0]-R[-1]C[0]"
        Cells(debut_potentiel + 1, 3).HorizontalAlignment = xlCenter
        Cells(debut_potentiel + 1, 4).FormulaR1C1 = "=R[-4]C[0]-R[-1]C[0]"
        Cells(debut_potentiel + 1, 4).HorizontalAlignment = xlCenter
     
        Cells(debut_potentiel + 2, 2).Formula = "=B" & (debut_potentiel + 1) & "/C" & (debut_potentiel + 7)
         Cells(debut_potentiel + 2, 2).HorizontalAlignment = xlCenter
         Cells(debut_potentiel + 2, 2).NumberFormat = "0.00"
        Cells(debut_potentiel + 2, 3).Formula = "=C" & (debut_potentiel + 1) & "/C" & (debut_potentiel + 7)
        Cells(debut_potentiel + 2, 3).HorizontalAlignment = xlCenter
         Cells(debut_potentiel + 2, 3).NumberFormat = "0.00"
        Cells(debut_potentiel + 2, 4).Formula = "=D" & (debut_potentiel + 1) & "/C" & (debut_potentiel + 7)
        Cells(debut_potentiel + 2, 4).HorizontalAlignment = xlCenter
         Cells(debut_potentiel + 2, 4).NumberFormat = "0.00"
     
     
     
    End Sub
    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
    Sub hypothese(debut, nom)
    Dim ind, i, f, vide, cellulevide, nbheure, Start As Integer
    Dim PLAGE As Range
    Dim c As Range
     
    ind = 1
    i = 0
    Worksheets("Calcul2").Rows.EntireRow.Delete
     
    Worksheets("Parametres").Range("A1").AutoFilter field:=2, Criteria1:=nom
    Set PLAGE = Worksheets("Parametres").Range("B2").CurrentRegion.SpecialCells(xlCellTypeVisible)
     
    For Each c In PLAGE
     If c.Column = 3 Then
        If c.Row > 1 Then
            Worksheets("Calcul2").Cells(ind, 1).Value = c.Value
            ind = ind + 1
        End If
     End If
    Next
     
    Worksheets("Calcul2").Range("A1").Select
    Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
     
     
    'test
    f = 1
    Do
    vide = IsEmpty(Worksheets("Calcul2").Cells(f, 1))
    f = f + 1
    Loop While vide = 0
    cellulevide = f - 2
     
    nbheure = 0
    Start = debut
    For f = 1 To cellulevide
        If Worksheets("Calcul2").Cells(f, 1).Value = nbheure Then
            'nb++
            Worksheets("Prevision").Cells(Start + i, 2).Value = Worksheets("Prevision").Cells(Start + i, 2).Value + 1
            Cells(debut_potentiel + 2, 4).HorizontalAlignment = xlCenter
            heure_totale = heure_totale + nbheure
        Else
            'aller a la ligne et nbheure= heures
            i = i + 1
            Worksheets("Prevision").Cells(Start + i, 1).Value = nom
            Worksheets("Prevision").Cells(Start + i, 1).Interior.ColorIndex = 42
            Worksheets("Prevision").Cells(Start + i, 1).HorizontalAlignment = xlCenter
     
            Worksheets("Prevision").Cells(Start + i, 2).Value = 1
            Worksheets("Prevision").Cells(Start + i, 2).HorizontalAlignment = xlCenter
            nbheure = Worksheets("Calcul2").Cells(f, 1).Value
            Worksheets("Prevision").Cells(Start + i, 3).Value = nbheure
            Worksheets("Prevision").Cells(Start + i, 3).HorizontalAlignment = xlCenter
            Worksheets("Prevision").Cells(Start + i, 4).FormulaR1C1 = "=R[0]C[-2]*R[0]C[-1]"
            Worksheets("Prevision").Cells(Start + i, 4).HorizontalAlignment = xlCenter
            heure_totale = heure_totale + nbheure
     
        End If
     
    Next
    hypothese_stop = Start + i
     
    End Sub

    Merci pour vos réponses

Discussions similaires

  1. Créer un batch qui s'exécute en mode admin sous Vista
    Par Boojum42 dans le forum Scripts/Batch
    Réponses: 3
    Dernier message: 02/04/2009, 15h03
  2. Code simple qui ne marche pas
    Par Zikas-r dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 16/12/2008, 01h35
  3. [A-07] Application plante sous xp et pas sous vista
    Par Syrrus dans le forum VBA Access
    Réponses: 8
    Dernier message: 14/10/2008, 10h45
  4. [POO] code valable sous IE et non sous Firefox
    Par picoule dans le forum Général JavaScript
    Réponses: 9
    Dernier message: 08/10/2008, 09h08
  5. Réponses: 2
    Dernier message: 06/01/2008, 00h13

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