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 :

Error 462 EXCEL


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Par défaut Error 462 EXCEL
    config excel 2003 et xp pro.

    bonjour,
    j expose le probleme du jour.
    j utilise excel pour remplir des labels dans word.
    pour ceci j utilise des signets et pour une raison ecologique je laisse le choix a l'utilisateur de remplir les signets qu il desire.
    Par exemple si il n a qu une etiquette sur sa feuille A4 il peut l utiliser au lieu de la jeter et apres je lui demande si il veu refaire des etiquettes et c est a ce deuxieme remplissage que mon prog plante avec une erreur 462.
    voir piece jointe
    Pièce jointe 25557

    voici mon 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
    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
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
     T1 = Sheet3.Cells(1, 1) & "_"
        T2 = Sheet3.Cells(2, 1) & "_"
        T3 = Sheet3.Cells(3, 1) & "\"
        C1 = Sheet3.Cells(4, 1) & "\"
        New_project = C1 & T1 & T2 & T3
     
     
     
        Dim appword As Object
        Set appword = New Word.Application
        Application.DisplayAlerts = True
        appword.ShowMe
        appword.Visible = True
        appword.Documents.Open Filename:="D:\My Documents\structure\Label\big and small label.doc"
     
     
        If CheckBox1 Or CheckBox2 Or CheckBox3 Or CheckBox4 Then
            ActiveDocument.Bookmarks("Project_Number1").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name1").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name1").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox5 Or CheckBox6 Or CheckBox7 Or CheckBox8 Then
            ActiveDocument.Bookmarks("Project_Number2").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name2").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name2").Range.Text = Sheet3.Cells(3, 1)
     
        End If
     
        If CheckBox9 Or CheckBox10 Or CheckBox11 Or CheckBox12 Then
            ActiveDocument.Bookmarks("Project_Number3").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name3").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name3").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox13 Or CheckBox14 Or CheckBox15 Or CheckBox16 Then
            ActiveDocument.Bookmarks("Project_Number4").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name4").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name4").Range.Text = Sheet3.Cells(3, 1)
     
        End If
     
        If CheckBox17 Or CheckBox18 Or CheckBox19 Or CheckBox20 Then
            ActiveDocument.Bookmarks("Project_Number5").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name5").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name5").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox21 Or CheckBox22 Or CheckBox23 Or CheckBox24 Then
            ActiveDocument.Bookmarks("Project_Number6").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name6").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name6").Range.Text = Sheet3.Cells(3, 1)
        End If
     
     
        If CheckBox25 Or CheckBox26 Or CheckBox27 Or CheckBox28 Then
            ActiveDocument.Bookmarks("Project_Number7").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name7").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name7").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox29 Or CheckBox30 Or CheckBox31 Or CheckBox32 Then
            ActiveDocument.Bookmarks("Project_Number8").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name8").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name8").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox33 Or CheckBox34 Or CheckBox35 Or CheckBox36 Then
            ActiveDocument.Bookmarks("Project_Number9").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name9").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name9").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox37 Or CheckBox38 Or CheckBox39 Or CheckBox40 Then
            ActiveDocument.Bookmarks("Project_Number10").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name10").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name10").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox41 Or CheckBox42 Or CheckBox43 Or CheckBox44 Then
            ActiveDocument.Bookmarks("Project_Number11").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name11").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name11").Range.Text = Sheet3.Cells(3, 1)
        End If
     
     
        If CheckBox1 Then _
           ActiveDocument.Bookmarks("Department1s").Range.Text = "Sales"
     
        If CheckBox2 Then _
           ActiveDocument.Bookmarks("Department1pm").Range.Text = "Project Management"
     
        If CheckBox3 Then _
           ActiveDocument.Bookmarks("Department1e").Range.Text = "Engineering"
     
        If CheckBox4 Then _
           ActiveDocument.Bookmarks("Department1q").Range.Text = "Quality"
     
        If CheckBox5 Then _
           ActiveDocument.Bookmarks("Department2s").Range.Text = "Sales"
     
        If CheckBox6 Then _
           ActiveDocument.Bookmarks("Department2pm").Range.Text = "Project Management"
     
        If CheckBox7 Then _
           ActiveDocument.Bookmarks("Department2e").Range.Text = "Engineering"
     
        If CheckBox8 Then _
           ActiveDocument.Bookmarks("Department2q").Range.Text = "Quality"
     
        If CheckBox9 Then _
           ActiveDocument.Bookmarks("Department3s").Range.Text = "Sales"
     
        If CheckBox10 Then _
           ActiveDocument.Bookmarks("Department3pm").Range.Text = "Project Management"
     
        If CheckBox11 Then _
           ActiveDocument.Bookmarks("Department3e").Range.Text = "Engineering"
     
        If CheckBox12 Then _
           ActiveDocument.Bookmarks("Department3q").Range.Text = "Quality"
     
        If CheckBox13 Then _
           ActiveDocument.Bookmarks("Department4s").Range.Text = "Sales"
     
        If CheckBox14 Then _
           ActiveDocument.Bookmarks("Department4pm").Range.Text = "Project Management"
     
        If CheckBox15 Then _
           ActiveDocument.Bookmarks("Department4e").Range.Text = "Engineering"
     
        If CheckBox16 Then _
           ActiveDocument.Bookmarks("Department4q").Range.Text = "Quality"
     
        If CheckBox17 Then _
           ActiveDocument.Bookmarks("Department5s").Range.Text = "Sales"
     
        If CheckBox18 Then _
           ActiveDocument.Bookmarks("Department5pm").Range.Text = "Project Management"
     
        If CheckBox19 Then _
           ActiveDocument.Bookmarks("Department5e").Range.Text = "Engineering"
     
        If CheckBox20 Then _
           ActiveDocument.Bookmarks("Department5q").Range.Text = "Quality"
     
        If CheckBox21 Then _
           ActiveDocument.Bookmarks("Department6s").Range.Text = "Sales"
     
        If CheckBox22 Then _
           ActiveDocument.Bookmarks("Department6pm").Range.Text = "Project Management"
     
        If CheckBox23 Then _
           ActiveDocument.Bookmarks("Department6e").Range.Text = "Engineering"
     
        If CheckBox24 Then _
           ActiveDocument.Bookmarks("Department6q").Range.Text = "Quality"
     
     
        If CheckBox25 Then _
           ActiveDocument.Bookmarks("Department7s").Range.Text = "Sales"
     
        If CheckBox26 Then _
           ActiveDocument.Bookmarks("Department7pm").Range.Text = "Project Management"
     
        If CheckBox27 Then _
           ActiveDocument.Bookmarks("Department7e").Range.Text = "Engineering"
     
        If CheckBox28 Then _
           ActiveDocument.Bookmarks("Department7q").Range.Text = "Quality"
     
        If CheckBox29 Then _
           ActiveDocument.Bookmarks("Department8s").Range.Text = "Sales"
     
        If CheckBox30 Then _
           ActiveDocument.Bookmarks("Department8pm").Range.Text = "Project Management"
     
        If CheckBox31 Then _
           ActiveDocument.Bookmarks("Department8e").Range.Text = "Engineering"
     
        If CheckBox32 Then _
           ActiveDocument.Bookmarks("Department8q").Range.Text = "Quality"
     
        If CheckBox33 Then _
           ActiveDocument.Bookmarks("Department9s").Range.Text = "Sales"
     
        If CheckBox34 Then _
           ActiveDocument.Bookmarks("Department9pm").Range.Text = "Project Management"
     
        If CheckBox35 Then _
           ActiveDocument.Bookmarks("Department9e").Range.Text = "Engineering"
     
        If CheckBox36 Then _
           ActiveDocument.Bookmarks("Department9q").Range.Text = "Quality"
     
        If CheckBox37 Then _
           ActiveDocument.Bookmarks("Department10s").Range.Text = "Sales"
     
        If CheckBox38 Then _
           ActiveDocument.Bookmarks("Department10pm").Range.Text = "Project Management"
     
        If CheckBox39 Then _
           ActiveDocument.Bookmarks("Department10e").Range.Text = "Engineering"
     
        If CheckBox40 Then _
           ActiveDocument.Bookmarks("Department10q").Range.Text = "Quality"
     
        If CheckBox41 Then _
           ActiveDocument.Bookmarks("Department11s").Range.Text = "Sales"
     
        If CheckBox42 Then _
           ActiveDocument.Bookmarks("Department11pm").Range.Text = "Project Management"
     
        If CheckBox43 Then _
           ActiveDocument.Bookmarks("Department11e").Range.Text = "Engineering"
     
        If CheckBox44 Then _
           ActiveDocument.Bookmarks("Department11q").Range.Text = "Quality"
     
        MsgBox "D:\My Documents\" & New_project
        msg = "Do you have finished to create label?"
        ans = MsgBox(msg, vbYesNo)
        If ans = vbYes Then
            appword.ChangeFileOpenDirectory "D:\My Documents\" & New_project
            ActiveDocument.SaveAs Filename:="Big And Small Label.doc"
            appword.Quit
            Unload UserForm3
        End If
     
        If ans = vbNo Then
        Unload UserForm3
            appword.ChangeFileOpenDirectory "D:\My Documents\" & New_project
            ActiveDocument.SaveAs Filename:="Big And Small Label1.doc"
            appword.Quit
            Unload UserForm3
            UserForm2.Show
        End If
     
    End Sub

    si quelqu un a une idee, sa m aiderai bcp ?

  2. #2
    Membre éclairé Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Par défaut re
    pour moi le probleme vient que le prog n arrive pas a reouvrir le doc appword en haut du sub au deuxieme tour.



    Quelqu un peut il m aider???

  3. #3
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Par défaut
    Oui, effectivement (pas très ergonomique ta procédure) : Tu pourrais utiliser deux select case

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Select case true
         Case CheckBox1, CheckBox2, CheckBox3, CheckBox4
            ActiveDocument.Bookmarks("Project_Number1").Range.Text = Sheet3.Cells(1, 1)
            ActiveDocument.Bookmarks("Customer_Name1").Range.Text = Sheet3.Cells(2, 1)
            ActiveDocument.Bookmarks("Project_Name1").Range.Text = Sheet3.Cells(3, 1)
         Case CheckBox5, CheckBox6, CheckBox7, CheckBox8
            ...
    Idem pour le second sur 1 seul check
    Ça évite à ta procédure de lire toutes les conditions pour n'en traiter qu'une seule
    Pour l'erreur, je ne vois pas. J'ai testé chez moi et n'ai pas de problème.

  4. #4
    Inactif  
    Avatar de ouskel'n'or
    Profil pro
    Inscrit en
    Février 2005
    Messages
    12 464
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 12 464
    Par défaut
    Ok, je viens de relire le code.
    Pour travailler sur un doc word, tu dois instancier le document, pas seulement l'application.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
       Dim appword as variant
       Dim appDoc as variant
        Set appword = New Word.Application
        Application.DisplayAlerts = True
        appword.ShowMe
        appword.Visible = True
        Set appDoc = appword.Documents.Open Filename:="D:\My Documents\structure\Label\big and small label.doc"
     
    Select case true
         Case appDoc.CheckBox1, appDoc.CheckBox2, appDoc.CheckBox3, appDoc.CheckBox4
            appDoc.Bookmarks("Project_Number1").Range.Text = Sheet3.Cells(1, 1)
            appDoc.Bookmarks("Customer_Name1").Range.Text = Sheet3.Cells(2, 1)
            appDoc.Bookmarks("Project_Name1").Range.Text = Sheet3.Cells(3, 1)
             ...
    Pas testé. Tu peux faire ça pour nous ?

  5. #5
    Membre éclairé Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Par défaut re
    atten je fais de l ergonomique la . car ta raison c est bordelique a lire et apres je tente ton instance...

    lol
    mais reste ds les parages.
    STP

  6. #6
    Membre éclairé Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Par défaut re
    deja j ai une ligne de code en rouge qd je fais l instance:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        Dim appword As Variant
       Dim appDoc As Variant
        Set appword = New Word.Application
        Application.DisplayAlerts = True
        appword.ShowMe
        appword.Visible = True
        Set appDoc = appword.Documents.Open Filename:="D:\My Documents\structure\Label\big and small label.doc"

  7. #7
    Membre chevronné
    Inscrit en
    Août 2007
    Messages
    360
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 360
    Par défaut
    Bonjour,

    Pourquoi les déclarer en variant??

    A+

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

Discussions similaires

  1. error export excel ->xml
    Par zidenne dans le forum Excel
    Réponses: 0
    Dernier message: 30/08/2012, 14h28
  2. Server Error in '/excel' Application.
    Par kika10 dans le forum ASP.NET
    Réponses: 5
    Dernier message: 02/05/2012, 14h09
  3. Excel - macro (format conditionnel - run-time error 1004)
    Par Chewi dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 01/09/2006, 19h18
  4. [VB.NET]Error lors du pilotage d'excel
    Par krfa1 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 01/05/2006, 12h58
  5. [Ole Excel]OLE Error avec numberformat
    Par ired dans le forum API, COM et SDKs
    Réponses: 5
    Dernier message: 13/03/2006, 20h55

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