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

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    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 ?
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    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???
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  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
    Points : 15 543
    Points
    15 543
    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
    Points : 15 543
    Points
    15 543
    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 averti Avatar de tomy7
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2008
    Messages
    540
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    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
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    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"
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

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

    Pourquoi les déclarer en variant??

    A+

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut bonne ?
    mais faut demander a ouskel nor

    en tt les cas sa marche pas chez moi 'l instance'
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  9. #9
    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
    Points : 15 543
    Points
    15 543
    Par défaut
    J'ai simplement oublié les parenthèses
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
       Set appDoc = appword.Documents.Open (Filename:="D:\My Documents\structure\Label\big and small label.doc")
    Tu testes mais je vérifie de mon côté
    A+

  10. #10
    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
    Points : 15 543
    Points
    15 543
    Par défaut
    J'ai testé
    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
    Sub openWord()
    Dim appDoc As Variant
    Dim appword As Variant
        Set appword = CreateObject("Word.Application")
        DoEvents
        Set appDoc = appword.Documents.Open(Filename:="D:\Doc\Britannica Universalis.doc")
        Application.DisplayAlerts = True
        appword.ShowMe
        appword.Visible = True
        '...
        '...
        appDoc.Close
        Set appDoc = Nothing
        appword.Quit
        Set appword = Nothing
    End Sub
    Tu dis
    A+

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut re
    je dois finir un truc qui va me prendre une petite heure et apres je test ta routine...


    reste ds les parrages!
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut re
    j ai fais sa pour le moment:

    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 appDoc As Variant
        Dim appword As Variant
        Set appword = New Word.Application
        DoEvents
        Set appDoc = appword.Documents.Open(Filename:="D:\My Documents\structure\Label\big and small label.doc")
        Application.DisplayAlerts = True
        appword.ShowMe
        appword.Visible = True
     
        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
    .
    .
    .


    mais je ne sais pas comment faire "le final":

    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
    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
            UserForm2.Show
        End If
    End Sub
    dois je remplacer les appword par appdoc?
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  13. #13
    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
    Points : 15 543
    Points
    15 543
    Par défaut
    Je ne connais pas ChangeFileOpenDirectory mais si "D:\My Documents\" & New_project est le nom du nouveau répertoire, je me simplifierais la vie :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
        If ans = vbYes Then
            appDoc.SaveAs Filename:="D:\My Documents\" & New_project & "Big And Small Label.doc"
            appword.Quit
            Unload UserForm3
        elseif ans = vbNo Then
            appDoc.SaveAs Filename:="D:\My Documents\" & New_project & "Big And Small Label1.doc"
            appword.Quit
            Unload UserForm3
            UserForm2.Show
        End If
    Vérifie que tu aies bien un "\" en fin de New_project
    A+

    Edit
    Où se trouve ton code ? Dans un userform ? Si c'est dans Userform3, c'est pas bon pour le passage de Userform3 à Userform2. Il faut mettre dans userform3 :Puis, dans Userform2_Activate,
    Sinon, dès que tu fermes Userform3, la suite du code ne s'exécutera pas
    A toutes fins utiles

    Edit (bis)
    Si le répertoire New_project n'existe pas et que tu veux le créer, c'est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Mkdir "D:\My Documents\" & New_project

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

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2008
    Messages : 540
    Points : 391
    Points
    391
    Par défaut re
    voici la solution:

    biensur sans toi ouskel'nor j y serai encore l anne prochaine !!!!!!!!!!!!!!!!


    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
    Private Sub Button_OK_Click()
     
        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 appdoc As Variant
        Dim appword As Variant
        Set appword = New Word.Application
        DoEvents
        Set appdoc = appword.Documents.Open(Filename:="D:\My Documents\structure\Label\big and small label.doc")
        Application.DisplayAlerts = True
        appword.ShowMe
        appword.Visible = True
     
        If CheckBox1 Or CheckBox2 Or CheckBox3 Or CheckBox4 Then
           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)
        End If
     
        If CheckBox5 Or CheckBox6 Or CheckBox7 Or CheckBox8 Then
           appdoc.Bookmarks("Project_Number2").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name2").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name2").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox9 Or CheckBox10 Or CheckBox11 Or CheckBox12 Then
           appdoc.Bookmarks("Project_Number3").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name3").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name3").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox13 Or CheckBox14 Or CheckBox15 Or CheckBox16 Then
           appdoc.Bookmarks("Project_Number4").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name4").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name4").Range.Text = Sheet3.Cells(3, 1)
        End If
     
     
        If CheckBox17 Or CheckBox18 Or CheckBox19 Or CheckBox20 Then
           appdoc.Bookmarks("Project_Number5").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name5").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name5").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox21 Or CheckBox22 Or CheckBox23 Or CheckBox24 Then
           appdoc.Bookmarks("Project_Number6").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name6").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name6").Range.Text = Sheet3.Cells(3, 1)
        End If
     
     
        If CheckBox25 Or CheckBox26 Or CheckBox27 Or CheckBox28 Then
           appdoc.Bookmarks("Project_Number7").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name7").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name7").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox29 Or CheckBox30 Or CheckBox31 Or CheckBox32 Then
           appdoc.Bookmarks("Project_Number8").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name8").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name8").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox33 Or CheckBox34 Or CheckBox35 Or CheckBox36 Then
           appdoc.Bookmarks("Project_Number9").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name9").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name9").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox37 Or CheckBox38 Or CheckBox39 Or CheckBox40 Then
           appdoc.Bookmarks("Project_Number10").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name10").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name10").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        If CheckBox41 Or CheckBox42 Or CheckBox43 Or CheckBox44 Then
           appdoc.Bookmarks("Project_Number11").Range.Text = Sheet3.Cells(1, 1)
           appdoc.Bookmarks("Customer_Name11").Range.Text = Sheet3.Cells(2, 1)
           appdoc.Bookmarks("Project_Name11").Range.Text = Sheet3.Cells(3, 1)
        End If
     
        Select Case True
     
        Case CheckBox1
           appdoc.Bookmarks("Department1s").Range.Text = "Sales"
        Case CheckBox5
           appdoc.Bookmarks("Department2s").Range.Text = "Sales"
        Case CheckBox9
           appdoc.Bookmarks("Department3s").Range.Text = "Sales"
        Case CheckBox13
           appdoc.Bookmarks("Department4s").Range.Text = "Sales"
        Case CheckBox17
           appdoc.Bookmarks("Department5s").Range.Text = "Sales"
        Case CheckBox21
           appdoc.Bookmarks("Department6s").Range.Text = "Sales"
        Case CheckBox25
           appdoc.Bookmarks("Department7s").Range.Text = "Sales"
        Case CheckBox29
           appdoc.Bookmarks("Department8s").Range.Text = "Sales"
        Case CheckBox33
           appdoc.Bookmarks("Department9s").Range.Text = "Sales"
        Case CheckBox37
           appdoc.Bookmarks("Department10s").Range.Text = "Sales"
        Case CheckBox41
           appdoc.Bookmarks("Department11s").Range.Text = "Sales"
        End Select
     
        Select Case True
        Case CheckBox2
           appdoc.Bookmarks("Department1pm").Range.Text = "Project Management"
        Case CheckBox6
           appdoc.Bookmarks("Department2pm").Range.Text = "Project Management"
        Case CheckBox10
           appdoc.Bookmarks("Department3pm").Range.Text = "Project Management"
        Case CheckBox14
           appdoc.Bookmarks("Department4pm").Range.Text = "Project Management"
        Case CheckBox18
           appdoc.Bookmarks("Department5pm").Range.Text = "Project Management"
        Case CheckBox22
           appdoc.Bookmarks("Department6pm").Range.Text = "Project Management"
        Case CheckBox26
           appdoc.Bookmarks("Department7pm").Range.Text = "Project Management"
        Case CheckBox30
           appdoc.Bookmarks("Department8pm").Range.Text = "Project Management"
        Case CheckBox34
           appdoc.Bookmarks("Department9pm").Range.Text = "Project Management"
        Case CheckBox38
           appdoc.Bookmarks("Department10pm").Range.Text = "Project Management"
        Case CheckBox42
           appdoc.Bookmarks("Department11pm").Range.Text = "Project Management"
        End Select
     
     
        Select Case True
        Case CheckBox3
           appdoc.Bookmarks("Department1e").Range.Text = "Engineering"
        Case CheckBox7
           appdoc.Bookmarks("Department2e").Range.Text = "Engineering"
        Case CheckBox11
           appdoc.Bookmarks("Department3e").Range.Text = "Engineering"
        Case CheckBox15
           appdoc.Bookmarks("Department4e").Range.Text = "Engineering"
        Case CheckBox19
           appdoc.Bookmarks("Department5e").Range.Text = "Engineering"
        Case CheckBox23
           appdoc.Bookmarks("Department6e").Range.Text = "Engineering"
        Case CheckBox27
           appdoc.Bookmarks("Department7e").Range.Text = "Engineering"
        Case CheckBox31
           appdoc.Bookmarks("Department8e").Range.Text = "Engineering"
        Case CheckBox35
           appdoc.Bookmarks("Department9e").Range.Text = "Engineering"
        Case CheckBox39
           appdoc.Bookmarks("Department10e").Range.Text = "Engineering"
        Case CheckBox43
           appdoc.Bookmarks("Department11e").Range.Text = "Engineering"
        End Select
     
        Select Case True
        Case CheckBox4
           appdoc.Bookmarks("Department1q").Range.Text = "Quality"
        Case CheckBox8
           appdoc.Bookmarks("Department2q").Range.Text = "Quality"
        Case CheckBox12
           appdoc.Bookmarks("Department3q").Range.Text = "Quality"
        Case CheckBox16
           appdoc.Bookmarks("Department4q").Range.Text = "Quality"
        Case CheckBox20
           appdoc.Bookmarks("Department5q").Range.Text = "Quality"
        Case CheckBox24
           appdoc.Bookmarks("Department6q").Range.Text = "Quality"
        Case CheckBox28
           appdoc.Bookmarks("Department7q").Range.Text = "Quality"
        Case CheckBox32
           appdoc.Bookmarks("Department8q").Range.Text = "Quality"
        Case CheckBox36
           appdoc.Bookmarks("Department9q").Range.Text = "Quality"
        Case CheckBox40
           appdoc.Bookmarks("Department10q").Range.Text = "Quality"
        Case CheckBox44
           appdoc.Bookmarks("Department11q").Range.Text = "Quality"
        End Select
     
        MsgBox "D:\My Documents\" & New_project
        msg = "Do you have finished to create label?"
        ans = MsgBox(msg, vbYesNo)
     
        If ans = vbYes Then
            appdoc.SaveAs Filename:="D:\My Documents\" & New_project & "Big And Small Label.doc"
            appword.Quit
            Unload UserForm3
        ElseIf ans = vbNo Then
            appdoc.SaveAs Filename:="D:\My Documents\" & New_project & "Big And Small Label1.doc"
            appword.Quit
            Unload UserForm3
            UserForm2.Show
        End If
    End Sub

    merci beaucoup
    tom

    "Barbar : The rest of the warrior"

    Into the wild....

  15. #15
    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
    Points : 15 543
    Points
    15 543
    Par défaut
    Citation Envoyé par mathieu44800 Voir le message
    Bonjour,

    Pourquoi les déclarer en variant??

    A+
    Parce que si tu mets Object, ça fonctionne pour l'appli, pas pour le document
    Et puis c'est plus simple, une variable de type variant, ce n'est même pas la peine de préciser le type qui est celui par défaut et qui s'adapte à la première utilisation qu'on en fait.
    Je précise tout de même qu'il est toujours mieux et le plus souvent nécessaire de préciser le type.

+ 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