Bonjour,
Savez-vous pourquoi cette macro ne fonctionne pas lorsque je veux associer un bouton sur celle-ci ?
En fait ce sont les conditions qu'il n'arrive pas à comprendre, sur chaque If il passe directement au End if alors que la condition est respectée ...
Si je déclare cette macro en mode Sub elle fonctionne parfaitement (comme ci-dessous) mais pas en Private Sub macro_Click() elle ne fonctionne pas

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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
Sub MARSEILLE()
 'Réduit toutes les fenêtres
         Call keybd_event(VK_LWIN, 0, 0, 0)
         Call keybd_event(77, 0, 0, 0)
         Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
 
Workbooks.Open "C:\OYAK\MEMO.xls"
Windows("MEMO.xls").Activate
ActiveWorkbook.CheckCompatibility = False
 
'Séparateur de milliers
With Application
        .ThousandsSeparator = "."
        .UseSystemSeparators = False
End With
 
Dim rng As Range
Dim rngFound_FRANCE As Range
Dim rngFound_IRLANDE As Range
Dim rngFound_SUISSE As Range
 
Set rng = Columns("A")
 
Set rngFound_FRANCE = rng.Find("FRANCE")
Set rngFound_IRLANDE = rng.Find("IRLANDE")
Set rngFound_SUISSE = rng.Find("SUISSE")
 
If rngFound_FRANCE Is Nothing Then
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
  Workbooks("MEMO.xls").Close savechanges:=True
Else:
Application.Run "MARSEILLE.xlsm!tcd_atr_v5_france"
Application.Run "MARSEILLE.xlsm!tcd_packing_list_france_v2"
Application.Run "MARSEILLE.xlsm!tcd_packing_list_france_BIS"
Application.Run "MARSEILLE.xlsm!tcd_Courrier_Oyak_France_V3"
 
Workbooks("MEMO.xls").Close savechanges:=True
 
 ' PUBLIPOSTAGE_DOCUMENTS MARSEILLE FRANCE
 
    Set WordApp = CreateObject("Word.Application")     '-- ouvre une session Word
    WordApp.Visible = True
 
    Set WordDoc = WordApp.Documents.Add    '-- crée un nouveau document
    WordApp.Run MacroName:="publipostage_atr_france_v7"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ATR MARSEILLE.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_packing_list_FRANCE"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\FRANSA FR.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_packing_list_france_BIS"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\FRANSA.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_courrier_oyak_france"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\FRANSA2.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
WordApp.Quit savechanges:=wdDoNotSaveChanges
Set WordApp = Nothing
End If
 
Workbooks.Open "C:\OYAK\MEMO.xls"
Windows("MEMO.xls").Activate
 
If rngFound_IRLANDE Is Nothing Then
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
  Workbooks("MEMO.xls").Close savechanges:=True
Else:
Application.Run "MARSEILLE.xlsm!tcd_packing_list_irlande"
Application.Run "MARSEILLE.xlsm!tcd_packing_list_irlande_BIS"
Application.Run "MARSEILLE.xlsm!tcd_atr_irlande_v2"
Application.Run "MARSEILLE.xlsm!tcd_Courrier_Oyak_Irlande"
 
Workbooks("MEMO.xls").Close savechanges:=True
 
 ' PUBLIPOSTAGE_DOCUMENTS MARSEILLE IRLANDE
 
    Set WordApp = CreateObject("Word.Application")     '-- ouvre une session Word
    WordApp.Visible = True
 
    Set WordDoc = WordApp.Documents.Add    '-- crée un nouveau document
    WordApp.Run MacroName:="Publipostage_packing_list_irlande"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ÿRLANDA FR.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_packing_list_irlande_BIS"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ÿRLANDA.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="publipostage_atr_irlande_v3"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ATR IRLANDE.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_courrier_oyak_irlande"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ÿRLANDA2.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
WordApp.Quit savechanges:=wdDoNotSaveChanges
Set WordApp = Nothing
End If
 
Workbooks.Open "C:\OYAK\MEMO.xls"
Windows("MEMO.xls").Activate
 
If rngFound_SUISSE Is Nothing Then
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
 Sheets.Add After:=ActiveSheet
  Workbooks("MEMO.xls").Close savechanges:=True
Else:
Application.Run "MARSEILLE.xlsm!tcd_eur1_v2_suisse"
Application.Run "MARSEILLE.xlsm!tcd_recap_facture_suisse_v2"
Application.Run "MARSEILLE.xlsm!tcd_packing_list_SUISSE"
Application.Run "MARSEILLE.xlsm!tcd_packing_list_SUISSE_BIS"
Application.Run "MARSEILLE.xlsm!tcd_Courrier_Oyak_SUISSE"
 
Workbooks("MEMO.xls").Close savechanges:=True
 
 ' PUBLIPOSTAGE_DOCUMENTS MARSEILLE SUISSE
 
    Set WordApp = CreateObject("Word.Application")     '-- ouvre une session Word
    WordApp.Visible = True
 
    Set WordDoc = WordApp.Documents.Add    '-- crée un nouveau document
    WordApp.Run MacroName:="Publipostage_eur1_V3_suisse"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\EUR1 SUISSE.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="publipostage_recap_facture_suisse_v4"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\EUR1 BÿLGÿLERÿ.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_packing_list_suisse"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ÿSVÿÇRE FR.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_packing_list_suisse_BIS_v2"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ÿSVÿÇRE.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
    Set WordDoc = WordApp.Documents.Add
    WordApp.Run MacroName:="Publipostage_courrier_oyak_suisse_v2"
    WordApp.ActiveDocument.SaveAs2 Filename:="C:\OYAK\MARSEILLE\ÿSVÿÇRE2.docx", FileFormat:= _
        wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
        :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
        :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
        SaveAsAOCELetter:=False, CompatibilityMode:=15
    WordApp.ActiveDocument.Close
    WordDoc.Close savechanges:=False
    Set WordDoc = Nothing
 
WordApp.Quit savechanges:=wdDoNotSaveChanges
Set WordApp = Nothing
End If
 
Set rng = Nothing
Set rngFound_FRANCE = Nothing
Set rngFound_IRLANDE = Nothing
Set rngFound_SUISSE = Nothing
 
MsgBox "Programme terminé"
Workbooks("MARSEILLE.xlsm").Close savechanges:=False
 
End Sub