Bonjour,

Je cherche un moyen de chercher une solution, pour déboguer ce message de VBA sur Excel 210 "Les informations de licence de ce composant sont introuvables. Vous n'avez pas la licence adéquate pour utiliser cette fonctionnalité dans l'environnement de création." souvent suivi du message "Erreur de compilation : Un composant ActiveX ne peut pas créer d'objet."

C'est arrivé après plusieurs jours de programmation.

Puis d'autres essais ont permis de continuer le code, mais le problème revient encore.

Hier , j'ai essayé pas à pas, :
- je fais un test complet sur l'application, et ça marche
- puis je rajoute les 4 lignes ci-dessous et le problème se reproduit, l'application est bloquée

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
Dim varNum As Long
Dim varObject As Object
Dim varString, comboSel As String
Dim varVariant As Variant
J'ai essayé d'explorer les pistes de l'aide :
- base de registre, DLL, virus
- exploration VBE7.DLL avec "dependencywalker"

Comment déboguer ?
Comment, surtout, obtenir l'élément en question ?
Comment avoir la certitude que c'est le code qui bloque, les licences, ou bien un effet de bord, virus, mauvaise installation, ... ????

Merci infiniment de votre aide.

Le code principal est sur un UserForm :

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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
Option Explicit
Dim varNum As Long
Dim varObject As Object
Dim varString, comboSel As String
Dim varVariant As Variant
 
Sub LectureTxt(nomFichier As String)
    ' ---------------------
    ' Lecture fichier texte
    ' ---------------------
    Dim intFic As Integer
    Dim ii As Byte
    Dim strLigne As String
    intFic = FreeFile
    ii = 1
    Open nomFichier For Input As intFic
    While Not EOF(intFic) And ii <= 5
        Line Input #intFic, strLigne
        MsgBox strLigne
        ii = ii + 1
    Wend
    Close intFic
End Sub
Sub LectureXls(nomFichier As String)
    ' --------------------------------
    ' Lecture fichier Excel, et autres
    ' --------------------------------
    Dim xls As Excel.Application
    Dim wk As Excel.Workbook
    Dim ws As Excel.Worksheet
    Dim numFields As Integer
    Dim numRows As Integer
    Dim curField As Integer
    Dim curRow As Integer
    Dim LineIn As String
    Dim tabFournisseur(1 To 50, 1 To 1000) As Variant
 
    On Error GoTo errHnd
 
    ' -----------------
    ' Ouverture fichier
    ' -----------------
    Set xls = CreateObject("Excel.Application")
    Set wk = xls.Workbooks.Open(nomFichier)
    xls.Visible = False
 
    ' -------------------------------------------
    ' Calcul nombre de lignes et nombre de champs
    ' -------------------------------------------
    numFields = 0
    numRows = 0
    While Not (IsEmpty(wk.ActiveSheet.Cells(1, numFields + 1)))
        numFields = numFields + 1
    Wend
    While Not (IsEmpty(wk.ActiveSheet.Cells(numRows + 1, 1)))
         numRows = numRows + 1
    Wend
    ' MsgBox "numrow : " & numRows & "<>  numfield : " & numFields
 
    ' ---------------------------------------------
    ' Remplissage du tableau avec 50 lignes maximum
    ' ---------------------------------------------
    If numRows > 50 Then
        numRows = 50
    End If
    For curRow = 1 To numRows
        For curField = 1 To numFields
            LineIn = LineIn & " " & wk.ActiveSheet.Cells(curRow, curField).Value
            'MsgBox wk.ActiveSheet.Cells(curRow, curField).Value
            tabFournisseur(curRow, curField) = wk.ActiveSheet.Cells(curRow, curField).Value
            Next curField
        ' MsgBox LineIn
        LineIn = ""
        Next curRow
    wk.Close
    ' MsgBox 1, UBound(tabFournisseur) & nomListe
 
    ' --------------------------------------
    ' Affichage du tableau dans la liste box
    ' --------------------------------------
    ListBox1.ColumnCount = UBound(tabFournisseur)
    ListBox1.BoundColumn = numFields
    ListBox1.List = tabFournisseur
 
    Exit Sub
errHnd:
    MsgBox "Erreur N° " & Err.Number & vbLf & Err.Description, , Err.Source
 
End Sub
Sub MajChoix(nomFichier As String)
 
    ' ------------------------------------
    ' Mise à jour de la liste des colonnes
    ' ------------------------------------
    Dim xls As Excel.Application
    Dim wk As Excel.Workbook
    Dim ws As Excel.Worksheet
    Dim numFields As Integer
    Dim numRows As Integer
    Dim curField As Integer
    Dim curRow As Integer
    Dim tabChoix() As Variant
 
    'MsgBox "Lecture param"
    On Error GoTo errHnd
 
    ' -----------------
    ' Ouverture fichier
    ' -----------------
    Set xls = CreateObject("Excel.Application")
    Set wk = xls.Workbooks.Open(nomFichier)
    xls.Visible = False
 
    ' -------------------------------------------
    ' Calcul nombre de lignes et nombre de champs
    ' -------------------------------------------
    numFields = 0
    numRows = 0
    While Not (IsEmpty(wk.ActiveSheet.Cells(1, numFields + 1)))
        numFields = numFields + 1
    Wend
    ' MsgBox "combo numfield : " & numFields
    ReDim tabChoix(numFields)
 
    ' ----------------------------------------
    ' Remplissage du tableau avec les colonnes
    ' ----------------------------------------
    For curField = 1 To numFields
        ' MsgBox wk.ActiveSheet.Cells(1, curField).Value
        tabChoix(curField) = curField & " " & wk.ActiveSheet.Cells(1, curField).Value
        Next curField
    wk.Close
    ' MsgBox "fin boucle"
    ' MsgBox "taille tabChoix : " & UBound(tabChoix)
 
    ' --------------------------------------
    ' Affichage du tableau dans la liste box
    ' --------------------------------------
    Me.ListBox9.ColumnCount = UBound(tabChoix)
    Me.ListBox9.List = tabChoix
 
    Exit Sub
errHnd:
    MsgBox "Erreur N° " & Err.Number & vbLf & Err.Description, , Err.Source
 
End Sub
Sub EcritureFic()
    Dim intFic As Integer
 
    intFic = FreeFile
    Open "D:\essai\monfichier.txt" For Output As intFic
    Print #intFic, "Une ligne"
    Close intFic
End Sub
 
 
Sub SelectFile()
 
    ' -----------------------------------------------
    ' Affichage de la fenêtre de sélection de fichier
    ' -----------------------------------------------
    Me.dlgFile.Filter = "Fichiers texte (*.txt)| *.txt|Fichiers csv (*.csv)| *.csv|tous (*.*)| *.*"
    Me.dlgFile.FilterIndex = 3
    Me.dlgFile.Flags = cdlOFNFileMustExist Or cdlOFNAllowMultiselect
    Me.dlgFile.ShowOpen
 
End Sub
 
Private Sub CommandButton1_Click()
 
    ' --------------------------------------------
    ' Appel de la sélection du fichier fournisseur
    ' --------------------------------------------
    Dim cnx As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset
 
    On Error GoTo err_click
    ' -----------------
    ' Connexion GENESYS
    ' -----------------
    Set cnx = New ADODB.Connection
    cnx.ConnectionString = "Provider=SQLOLEDB.1;Password=xx;Persist Security Info=True;User ID=xx;Initial Catalog=xx;Data Source=xx;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=BE05;Use Encryption for Data=False;Tag with column collation when possible=False"
    cnx.Open
    Set rs = cnx.OpenSchema(adSchemaTables)
    rs.Close
    cnx.Close
    Set cnx = Nothing
 
    ' ----------------------
    ' Sélectioner un fichier
    ' ----------------------
    SelectFile
    ' Mettre le nom du fichier fournisseur dans Label14
    Label14.Caption = Me.dlgFile.Filename
    ' Remplir ListBox1
    Call LectureXls(Me.dlgFile.Filename)
 
    ' -------------------------------------
    ' Activer la saisie des correspondances
    ' -------------------------------------
    Me.CommandButton2.Enabled = True
 
    Exit Sub
 
err_click:
    MsgBox "Erreur d'exécution No " & Err.Number & vbCrLf & Err.Description, vbCritical, Me.Caption
End Sub
Sub BoutonMoins(nomListe As Object)
 
    ' ----------------------------------------
    ' Supprimer la correspondance sélectionnée
    ' ----------------------------------------
    Dim element_select As Boolean
    Dim nb_elements, ii   As Integer
 
    element_select = False
    nb_elements = nomListe.ListCount
    ' ------------------------------------
    ' Suppression de l'élément sélectionné
    ' ------------------------------------
    For ii = 0 To nb_elements - 1
        If nomListe.Selected(ii) = True Then
            element_select = True
            nomListe.RemoveItem (ii)
       End If
    Next
 
    ' --------------------------------------
    ' Message s'il n'y a rien de sélectionné
    ' --------------------------------------
    If element_select = False Then
        MsgBox "Vous n'avez rien sélectionné en suppression"
        Exit Sub
    End If
End Sub
 
Private Sub CommandButton10_Click()
    ' ------------------------------------------
    ' Ajouter une correspondance Famille_Produit
    ' ------------------------------------------
    Call BoutonPlus(Me.ListBox6.Object)
End Sub
 
Private Sub CommandButton11_Click()
    ' -------------------------------------------------------
    ' Ajouter une correspondance Famille_Produit_Regroupement
    ' -------------------------------------------------------
    Call BoutonPlus(Me.ListBox7.Object)
End Sub
 
Private Sub CommandButton12_Click()
    ' ------------------------------------
    ' Ajouter une correspondance Nom_Court
    ' ------------------------------------
    Call BoutonPlus(Me.ListBox8.Object)
End Sub
 
Private Sub CommandButton13_Click()
    ' ------------------------------------------
    ' Supprimer une correspondance Ref_Fabricant
    ' ------------------------------------------
    Call BoutonMoins(Me.ListBox10.Object)
End Sub
 
Private Sub CommandButton14_Click()
    ' -----------------------------------
    ' Supprimer une correspondance Marque
    ' -----------------------------------
    Call BoutonMoins(Me.ListBox4.Object)
End Sub
 
Private Sub CommandButton15_Click()
    ' ----------------------------------------------
    ' Supprimer une correspondance N_Famille_Produit
    ' ----------------------------------------------
    Call BoutonMoins(Me.ListBox5.Object)
End Sub
 
Private Sub CommandButton16_Click()
    ' --------------------------------------------
    ' Supprimer une correspondance Famille_Produit
    ' --------------------------------------------
    Call BoutonMoins(Me.ListBox6.Object)
End Sub
 
Private Sub CommandButton17_Click()
    ' ---------------------------------------------------------
    ' Supprimer une correspondance Famille_Produit_Regroupement
    ' ---------------------------------------------------------
    Call BoutonMoins(Me.ListBox7.Object)
End Sub
 
Private Sub CommandButton18_Click()
    ' --------------------------------------
    ' Supprimer une correspondance Nom_Court
    ' --------------------------------------
    Call BoutonMoins(Me.ListBox8.Object)
End Sub
 
Private Sub CommandButton19_Click()
    ' -----------------------------------
    ' Ajouter une correspondance Nom_Long
    ' -----------------------------------
    Call BoutonPlus(Me.ListBox11.Object)
End Sub
 
Private Sub CommandButton2_Click()
 
    ' ------------------------------------
    ' Initialisation des colonnes de choix
    ' ------------------------------------
    ' Sélectionner un fichier
    ' ------------------------------------
    SelectFile
    ' -----------------------------------------
    ' Remplir liste avec les entetes de colonne
    ' -----------------------------------------
    Call MajChoix(Me.dlgFile.Filename)
 
    Me.ListBox4.Clear
    Me.ListBox5.Clear
    Me.ListBox6.Clear
    Me.ListBox7.Clear
    Me.ListBox8.Clear
    Me.ListBox10.Clear
    Me.ListBox11.Clear
    Me.ListBox12.Clear
    Me.ListBox13.Clear
    Me.ListBox14.Clear
    Me.ListBox15.Clear
    Me.ListBox16.Clear
    Me.ListBox17.Clear
 
    ' ---------------------------------------
    ' Activer la simulation et la mise à jour
    ' ---------------------------------------
    Me.CommandButton4.Enabled = True
    Me.CommandButton5.Enabled = True
 
    Exit Sub
 
err_click:
    MsgBox "Erreur d'exécution No " & Err.Number & vbCrLf & Err.Description, vbCritical, Me.Caption
End Sub
 
Private Sub CommandButton20_Click()
    ' ---------------------------------
    ' Supprimer correspondance Nom_Long
    ' ---------------------------------
    Call BoutonMoins(Me.ListBox11.Object)
End Sub
 
Private Sub CommandButton21_Click()
    ' ---------------------------------
    ' Ajouter correspondance Prix_Tarif
    ' ---------------------------------
    Call BoutonPlus(Me.ListBox12.Object)
End Sub
 
Private Sub CommandButton22_Click()
    ' -----------------------------------
    ' Supprimer correspondance Prix_Tarif
    ' -----------------------------------
    Call BoutonMoins(Me.ListBox12.Object)
End Sub
 
Private Sub CommandButton23_Click()
    ' ----------------------------
    ' Ajouter correspondance Unite
    ' ----------------------------
    Call BoutonPlus(Me.ListBox13.Object)
End Sub
 
Private Sub CommandButton24_Click()
    ' ------------------------------
    ' Supprimer correspondance Unite
    ' ------------------------------
    Call BoutonMoins(Me.ListBox13.Object)
End Sub
 
Private Sub CommandButton25_Click()
    ' --------------------------------------
    ' Ajouter correspondance Delai_Livraison
    ' --------------------------------------
    Call BoutonPlus(Me.ListBox14.Object)
End Sub
 
Private Sub CommandButton26_Click()
    ' ----------------------------------------
    ' Supprimer correspondance Delai_Livraison
    ' ----------------------------------------
    Call BoutonMoins(Me.ListBox14.Object)
End Sub
 
Private Sub CommandButton27_Click()
    ' ----------------------------
    ' Ajouter correspondance Poids
    ' ----------------------------
    Call BoutonPlus(Me.ListBox15.Object)
End Sub
 
Private Sub CommandButton28_Click()
    ' ------------------------------
    ' Supprimer correspondance Poids
    ' ------------------------------
    Call BoutonMoins(Me.ListBox15.Object)
End Sub
 
Private Sub CommandButton29_Click()
    ' ----------------------------------
    ' Ajouter correspondance Suppression
    ' ----------------------------------
    Call BoutonPlus(Me.ListBox16.Object)
End Sub
 
Private Sub CommandButton30_Click()
    ' ------------------------------------
    ' Supprimer correspondance Suppression
    ' ------------------------------------
    Call BoutonMoins(Me.ListBox16.Object)
End Sub
 
Private Sub CommandButton31_Click()
    Call BoutonPlus(Me.ListBox17.Object)
End Sub
 
Private Sub CommandButton32_Click()
    ' --------------------------------------
    ' Supprimer correspondance N_ProduitLong
    ' --------------------------------------
    Call BoutonMoins(Me.ListBox17.Object)
End Sub
 
Private Sub CommandButton33_Click()
    ' ----------------
    ' Aide application
    ' ----------------
    Application.Help ("C:\Documents and Settings\AM\Mes documents\GB\Help\Genesys_Interface_Tarif_Fournisseur.chm")
End Sub
 
Private Sub CommandButton34_Click()
    ' ---------------------------------------
    ' Saisir les informations base de données
    ' ---------------------------------------
    FRM_base.TextBox1.Text = nomBase
    FRM_base.TextBox2.Text = pwdBase
    FRM_base.TextBox3.Text = userBase
    FRM_base.Show
    nomBase = FRM_base.TextBox1.Text
    pwdBase = FRM_base.TextBox2.Text
    userBase = FRM_base.TextBox3.Text
    MsgBox nomBase & vbCrLf & pwdBase, vbInformation, "trace base"
End Sub
 
Private Sub CommandButton4_Click()
 
    ' -------------------------------------------------
    ' Simuler la mise à jour de la table MFPS_CATALOGUE
    ' -------------------------------------------------
    Dim resultatMaj As Variant
    Dim ii As Integer
 
    ' ---------------------------------------------------------------------------------
    ' Appel de la Fonction de mise en forme des requêtes et transaction vers SQL Server
    ' ---------------------------------------------------------------------------------
    resultatMaj = MajCatalogue(1)
 
    ' ------------------------------------
    ' Affichage des messages dans ListBox2
    ' ------------------------------------
    If Not IsEmpty(resultatMaj) Then
        Me.ListBox2.ColumnCount = 2
        Me.ListBox2.BoundColumn = 2
        Me.ListBox2.List = resultatMaj
    End If
    Exit Sub
End Sub
 
Private Sub CommandButton5_Click()
    ' ---------------------------------------------------
    ' Effectuer la mise à jour de la table MFPS_CATALOGUE
    ' ---------------------------------------------------
    Dim resultatMaj As Variant
    Dim ii As Integer
 
    ' ---------------------------------------------------------------------------------
    ' Appel de la Fonction de mise en forme des requêtes et transaction vers SQL Server
    ' ---------------------------------------------------------------------------------
    resultatMaj = MajCatalogue(0)
 
    ' ------------------------------------
    ' Affichage des messages dans ListBox2
    ' ------------------------------------
    If Not IsEmpty(resultatMaj) Then
        Me.ListBox2.ColumnCount = UBound(resultatMaj)
        Me.ListBox2.BoundColumn = 2
        Me.ListBox2.List = resultatMaj
    End If
 
    Exit Sub
End Sub
 
Function MajCatalogue(typeMaj As Integer) As Variant
 
    ' -------------------------------------------
    ' Mise à jour CATALOGUE / Simulation / Réelle
    ' -------------------------------------------
    Dim xls As Excel.Application
    Dim wk As Excel.Workbook
    Dim ws As Excel.Worksheet
    Dim ii, numFields As Integer
    Dim numRows As Integer
    Dim curField As Integer
    Dim curRow, curTab As Integer
    Dim LineIn As String
    Dim nomFichier, valChamp As String
    Dim tabFournisseur() As Variant
    Dim tabBox(13) As Object
    Dim tabValeurs() As Variant
    Dim tabMaj(), tabMessage() As Variant
    Dim numReq, cptMessage, cptInsert, cptUpdate As Integer
    Dim reqSql, majSql, creSql As String
    Dim flagInsert, flagParam As Boolean
    Dim colNum, nbSecondes, nbMinutes As Double
    Dim heureDebut As Date
    Dim heureFin As Date
 
    Me.ListBox2.Clear
 
    Dim cnx As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset
 
    ' MsgBox "balayage fichier fournisseur", vbYesNo, "trace button4"
    On Error GoTo errHnd
 
    ' -----------------
    ' Connexion GENESYS
    ' -----------------
    If nomBase = "" Or userBase = "" Or pwdBase = "" Then
        MsgBox "Base         : " & nomBase & vbCrLf & "Utilisateur  : " & userBase & vbCrLf & "Mot de passe : " & pwdBase, vbExclamation, "Base inaccessible"
        Exit Function
    End If
    Set cnx = New ADODB.Connection
    cnx.ConnectionString = "Provider=SQLOLEDB.1;Password=" & pwdBase & ";Persist Security Info=True;User ID=" & userBase & ";Initial Catalog=" & nomBase & ";Data Source=xx;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=BE05;Use Encryption for Data=False;Tag with column collation when possible=False"
    MsgBox cnx.ConnectionString, vbInformation, "trace cnx param"
    ' cnx.ConnectionString = "Provider=SQLOLEDB.1;Password=xx;Persist Security Info=True;User ID=xx;Initial Catalog=xx;Data Source=xx;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=BE05;Use Encryption for Data=False;Tag with column collation when possible=False"
    ' MsgBox cnx.ConnectionString, vbInformation, "trace cnx fixe"
 
    cnx.Open
    Set rs = New ADODB.Recordset
 
    ' -----------------
    ' Ouverture fichier
    ' -----------------
    nomFichier = Label14.Caption
    Set xls = CreateObject("Excel.Application")
    Set wk = xls.Workbooks.Open(nomFichier)
    xls.Visible = False
 
    ' -----------------------------
    ' Chargement fichier en tableau
    ' -----------------------------
    numFields = 0
    numRows = 0
    While Not (IsEmpty(wk.ActiveSheet.Cells(1, numFields + 1)))
        numFields = numFields + 1
    Wend
    While Not (IsEmpty(wk.ActiveSheet.Cells(numRows + 1, 1)))
         numRows = numRows + 1
    Wend
 
    ReDim tabFournisseur(numRows, numFields)
    ReDim tabValeurs(numRows + 1, 14)
    ReDim tabMaj(numRows)
    ' MsgBox "numrow : " & numRows & "  numfield : " & numFields, vbInformation, "trace lignes colonnes"
 
    For curRow = 1 To numRows
        For curField = 1 To numFields
            LineIn = LineIn & " " & wk.ActiveSheet.Cells(curRow, curField).Value
            ' MsgBox wk.ActiveSheet.Cells(curRow, curField).Value
            If curRow > 1 Then
                tabFournisseur(curRow - 1, curField - 1) = wk.ActiveSheet.Cells(curRow, curField).Value
            End If
            Next curField
        ' MsgBox LineIn
        LineIn = ""
        Next curRow
    wk.Close
 
    ' -----------------------------------------
    ' Initialisation entête tableau des valeurs
    ' -----------------------------------------
    tabValeurs(0, 1) = "ref_fabricant"
    tabValeurs(0, 2) = "marque"
    tabValeurs(0, 3) = "n_famille_produit"
    tabValeurs(0, 4) = "famille_produit"
    tabValeurs(0, 5) = "famille_produit_regroupement"
    tabValeurs(0, 6) = "nom_court"
    tabValeurs(0, 7) = "nom_long"
    tabValeurs(0, 8) = "prix_tarif"
    tabValeurs(0, 9) = "unite"
    tabValeurs(0, 10) = "delai_livraison"
    tabValeurs(0, 11) = "poids"
    tabValeurs(0, 12) = "suppression"
    tabValeurs(0, 13) = "n_produit"
    ' ----------------------------------
    ' Initialisation tableau des ListBox
    ' ----------------------------------
    Set tabBox(0) = ListBox10.Object
    Set tabBox(1) = ListBox4.Object
    Set tabBox(2) = ListBox5.Object
    Set tabBox(3) = ListBox6.Object
    Set tabBox(4) = ListBox7.Object
    Set tabBox(5) = ListBox8.Object
    Set tabBox(6) = ListBox11.Object
    Set tabBox(7) = ListBox12.Object
    Set tabBox(8) = ListBox13.Object
    Set tabBox(9) = ListBox14.Object
    Set tabBox(10) = ListBox15.Object
    Set tabBox(11) = ListBox16.Object
    Set tabBox(12) = ListBox17.Object
    ' ---------------------------------
    ' Controle de saisie des paramètres
    ' ---------------------------------
    flagParam = False
    For curTab = 0 To UBound(tabBox) - 1
        If tabBox(curTab).ListCount > 0 Then flagParam = True
        Next curTab
    If Not flagParam Then
        MsgBox "Veuillez renseigner les correspondances Fournisseur - MFPS-CATALOGUE", vbInformation, "Renseigner les correspondances"
        Exit Function
    End If
    ' -------------------------------------------------------------------------------------------
    ' Chargement tableau des valeurs en croisant tableau fournisseur avec les listbox paramètrage
    ' -------------------------------------------------------------------------------------------
    For curRow = 1 To UBound(tabFournisseur)
        ' MsgBox curRow & " " & tabFournisseur(curRow, 0), vbInformation, "trace val"
        ' -----------------
        ' Valeur des champs
        ' -----------------
        For curTab = 0 To UBound(tabBox) - 1
            If tabBox(curTab).ListCount > 0 Then
               For ii = 0 To tabBox(curTab).ListCount - 1
                   If tabBox(curTab).List(ii) <> "" Then
                       If IsNumeric(Left(tabBox(curTab).List(ii), 1)) Then
                           tabValeurs(curRow, curTab + 1) = tabValeurs(curRow, curTab + 1) & tabFournisseur(curRow, Left(tabBox(curTab).List(ii), 1) - 1)
                           ' MsgBox "tab : " & curTab & " count : " & tabBox(curTab).ListCount & " fourn : " & tabFournisseur(curRow, Left(tabBox(curTab).List(ii), 1) - 1), vbInformation, "trace box num "
                       Else
                           If tabBox(curTab).List(ii) <> "" Then
                               tabValeurs(curRow, curTab + 1) = tabBox(curTab).List(ii)
                               ' MsgBox "tab : " & curTab & " count : " & tabBox(curTab).ListCount & " fourn : " & tabFournisseur(curRow, Left(tabBox(curTab).List(ii), 1) - 1), vbInformation, "trace box char "
                           End If
                       End If
                   End If
                Next ii
            End If
            Next curTab
        Next curRow
 
    ' ------------------------------------
    ' Vérification dans la table CATALOGUE
    ' ------------------------------------
    cptInsert = 0
    cptUpdate = 0
    For curRow = 1 To UBound(tabValeurs, 1)
        ' ----------------------------------------------------------------------
        ' Lecture table CATALOGUE et mise à jour de tabValeurs 0=insert 1=update
        ' ----------------------------------------------------------------------
        reqSql = "select * from mfps_catalogue where " & tabValeurs(0, 1) & "= '" & tabValeurs(curRow, 1) & "'" & _
            " and " & tabValeurs(0, 2) & "='" & tabValeurs(curRow, 2) & "'"
        rs.Open (reqSql), cnx
        flagInsert = True
        While Not rs.EOF
            ' MsgBox "trace read : " & rs.Fields(0), vbOKCancel
            flagInsert = False
            rs.MoveNext
        Wend
        rs.Close
        If flagInsert Then
            tabValeurs(curRow, 0) = 0
            cptInsert = cptInsert + 1
        Else
            tabValeurs(curRow, 0) = 1
            cptUpdate = cptUpdate + 1
        End If
        Next curRow
 
    ' --------------------------------
    ' Mise à jour tableau des requêtes
    ' --------------------------------
    numReq = 0
    creSql = "insert into mfps_catalogue ("
    majSql = "update mfps_catalogue set "
    For curField = 1 To UBound(tabValeurs, 2)
        creSql = creSql & tabValeurs(0, curField)
        If curField < UBound(tabValeurs, 2) - 1 Then creSql = creSql & ","
        Next curField
    creSql = creSql & ") values ( "
    ' MsgBox "début requêtes", vbInformation, "trace cresql init"
    For curRow = 1 To UBound(tabValeurs, 1)
        If tabValeurs(curRow, 1) <> "" Then
            ' ----------------------------------
            ' Mise en forme requête de INSERTION
            ' ----------------------------------
            If tabValeurs(curRow, 0) = 0 Then
                reqSql = creSql
                MsgBox "insert : " & tabValeurs(curRow, 2), vbInformation, "trace cresql boucle"
                For curField = 1 To UBound(tabValeurs, 2) - 1
                    If curField = 3 Or curField = 8 Or curField = 10 Or curField = 11 Or curField = 13 Then
                        ' MsgBox tabValeurs(0, curField) & "  " & tabValeurs(curRow, curField), vbInformation, "trace insert num"
                        If IsEmpty(tabValeurs(curRow, curField)) Or _
                            IsNull(tabValeurs(curRow, curField)) Or _
                            tabValeurs(curRow, curField) = "" Then
                            colNum = 0
                        Else
                            ' ---------------------------------------
                            ' Remplacement de la virgule par le point
                            ' ---------------------------------------
                            ' MsgBox tabValeurs(0, curField) & "  " & tabValeurs(curRow, curField), vbInformation, "trace avant replace num"
                            colNum = Replace(tabValeurs(curRow, curField), ",", ".")
                            ' colNum = tabValeurs(curRow, curField)
                        End If
                        reqSql = reqSql & colNum
                        If Not IsNumeric(colNum) Then
                            MsgBox tabValeurs(0, curField) & " : " & colNum & vbCrLf & reqSql, vbExclamation, "Erreur valeur non numerique "
                            Resume errHnd
                        End If
                    Else
                        ' MsgBox tabValeurs(curRow, curField), vbInformation, "trace insert char"
                        ' -------------------------------------
                        ' Remplacement de la quote par un blanc
                        ' -------------------------------------
                        valChamp = Replace(tabValeurs(curRow, curField), "'", " ")
                        reqSql = reqSql & "'" & valChamp & "'"
                        If curField = 1 And IsEmpty(valChamp) Or IsNull(valChamp) Or valChamp = "" Then
                            MsgBox tabValeurs(0, curField) & " : " & valChamp & vbCrLf & reqSql, vbExclamation, "Erreur Référence Article non renseignée"
                            Resume errHnd
                        End If
                    End If
                    If curField < UBound(tabValeurs, 2) - 1 Then reqSql = reqSql & ","
                    Next curField
                reqSql = reqSql & ")"
            ' -------------------------------
            ' Mise en forme requête de UPDATE
            ' -------------------------------
            Else
                reqSql = majSql
                If IsEmpty(tabValeurs(curRow, 1)) Or IsNull(tabValeurs(curRow, 1)) Or tabValeurs(curRow, 1) = "" Then
                    MsgBox tabValeurs(0, 1) & " : " & tabValeurs(curRow, 1) & vbCrLf & reqSql, vbExclamation, "Erreur Référence Article non renseignée"
                            Resume errHnd
                        End If
                For curField = 2 To UBound(tabValeurs, 2) - 1
                ' MsgBox "boucle requête 1 field : " & curField & tabValeurs(curRow, curField), vbInformation, "trace requête"
                    If curField = 3 Or curField = 8 Or curField = 10 Or curField = 11 Or curField = 13 Then
                        ' MsgBox tabValeurs(curRow, curField), vbInformation, "trace update num"
                        If IsEmpty(tabValeurs(curRow, curField)) Or _
                            IsNull(tabValeurs(curRow, curField)) Or _
                            tabValeurs(curRow, curField) = "" Then
                            colNum = 0
                        Else
                            ' ---------------------------------------
                            ' Remplacement de la virgule par le point
                            ' ---------------------------------------
                            colNum = Replace(tabValeurs(curRow, curField), ",", ".")
                            'colNum = tabValeurs(curRow, curField)
                        End If
                        reqSql = reqSql & tabValeurs(0, curField) & "=" & colNum
                        If Not IsNumeric(colNum) Then
                            MsgBox tabValeurs(0, curField) & " : " & colNum & vbCrLf & reqSql, vbExclamation, "Erreur valeur non numerique "
                            Resume errHnd
                        End If
                    Else
                        ' MsgBox tabValeurs(curRow, curField), vbInformation, "trace update char"
                        ' -------------------------------------
                        ' Remplacement de la quote par un blanc
                        ' -------------------------------------
                        valChamp = Replace(tabValeurs(curRow, curField), "'", " ")
                        reqSql = reqSql & tabValeurs(0, curField) & "='" & valChamp & "'"
                    End If
                    If curField < UBound(tabValeurs, 2) - 1 Then reqSql = reqSql & ","
                    Next curField
                reqSql = reqSql & " where " & tabValeurs(0, 1) & " = '" & tabValeurs(curRow, 1) & "'"
                reqSql = reqSql & " and  " & tabValeurs(0, 2) & " = '" & tabValeurs(curRow, 2) & "'"
            End If
        End If
        tabMaj(numReq) = reqSql
        numReq = numReq + 1
        Next curRow
    ' MsgBox "requêtes : " & numReq & "  type maj : " & typeMaj, vbInformation, "trace compteur requêtes"
 
    ' -------------------------------------------------------------------------------
    'typeMaj=0 --> Mise à jour de la table CATALOGUE ou bien typeMaj=1 --> Simulation
    ' -------------------------------------------------------------------------------
 
    ReDim tabMessage(UBound(tabMaj))
    cnx.BeginTrans
        heureDebut = Now
        For curRow = 0 To UBound(tabMaj)
            MsgBox "ligne " & curRow & "   " & tabMaj(curRow), vbOKCancel, "trace tabMaj avant"
            cnx.Execute tabMaj(curRow)
            Next curRow
    heureFin = Now
    If typeMaj = 1 Then
        cnx.RollbackTrans
    Else
        cnx.CommitTrans
    End If
 
    ' --------------------------------
    ' Remplissage tableau des messages
    ' --------------------------------
    nbMinutes = DateDiff("n", heureDebut, heureFin)
    nbSecondes = DateDiff("s", heureDebut, heureFin)
    tabMessage(0) = "Nombre de créations : " & cptInsert
    tabMessage(1) = "Nombre de mises à jour  : " & cptUpdate
    tabMessage(2) = "Heure début de traitement  : " & heureDebut
    tabMessage(3) = "Heure fin de traitement  : " & heureFin
    tabMessage(4) = "Durée du traitement  --> " & nbMinutes & " minutes : " & nbSecondes & " secondes"
    MajCatalogue = tabMessage
 
    ' ----------------------
    ' Fermeture base GENESYS
    ' ----------------------
    cnx.Close
    Set cnx = Nothing
    Exit Function
 
errHnd:
    MsgBox "Erreur d'exécution No " & Err.Number & vbCrLf & Err.Description, vbCritical, Me.Caption
 
End Function
Sub BoutonPlus(nomListe As Object)
 
    ' ----------------------------------------------------------
    ' Ajouter une sélection ListBox9 ou ComboBox1 dans une liste
    ' ----------------------------------------------------------
    Dim element_select As Boolean
    Dim nb_elements, ii   As Integer
 
    element_select = False
    nb_elements = ListBox9.ListCount
    ' ------------------------------------
    'Vérifie si un élément est sélectionné
    ' ------------------------------------
    For ii = 0 To nb_elements - 1
        If ListBox9.Selected(ii) = True Then
            element_select = True
            nomListe.AddItem ListBox9.List(ii, 0)
            ListBox9.Selected(ii) = False
            'MsgBox ListBox9.Value
       End If
    Next
 
    ' -----------------------------
    ' Copier la valeur de ComboBox1
    ' -----------------------------
    nomListe.AddItem ComboBox1.Value
 
    ' -----------------------------------------
    ' Message si aucun item n'a été sélectionné
    ' -----------------------------------------
    If nomListe.ListCount = 0 Then
        MsgBox "Vous n'avez rien sélectionné à ajouter"
        Exit Sub
    End If
 
End Sub
Private Sub CommandButton7_Click()
    ' ------------------------------------
    ' Ajouter correspondance Ref_Fabricant
    ' ------------------------------------
    Call BoutonPlus(Me.ListBox10.Object)
 
End Sub
 
Private Sub CommandButton8_Click()
    ' -----------------------------
    ' Ajouter correspondance Marque
    ' -----------------------------
    Call BoutonPlus(Me.ListBox4.Object)
End Sub
 
Private Sub CommandButton9_Click()
    ' ----------------------------------------
    ' Ajouter correspondance N_Famille_Produit
    ' ----------------------------------------
    Call BoutonPlus(Me.ListBox5.Object)
End Sub
 
 
Private Sub UserForm_Initialize()
    nomBase = "xx"
    userBase = "xx"
    pwdBase = "xx"
End Sub