Option Explicit
Dim Fichier As String, Nom As String, Chemin As String
Dim Wks As Workbook, Sh As Worksheet
'---------------------------------------------------------
Sub Ouvrir_Fichier()
Nom = CBlistefournisseurs.Text
Fichier = Nom & ".xlsx"
' Chemin = ThisWorkbook.Path & "\fournisseurs\"
Chemin = "C:\Facturation\base\fournisseurs\"
'Set Wks = Workbooks.Open(Chemin & Fichier)
End Sub
Private Sub CBlistefournisseurs_Change()
If CBlistefournisseurs <> "" Then Ouvrir_Fichier
End Sub
Private Sub CommandButton1_Click()
Dim L As Long, n As Long, i As Long, Fichier
L = ListBox1.ListIndex
If L < 1 Then MsgBox "vous n'avez rien sélectionné", 16, "oups...": Exit Sub
n = ListBox1.ListCount
Application.ScreenUpdating = False
On Error Resume Next
Set Sh = ActiveWorkbook.ActiveSheet
With Sh
L = .Cells(8, 2).End(xlUp)
For i = 0 To n - 1
If ListBox1.Selected(i) Then
L = L + 1
.Cells(L, 2) = ListBox1.List(i)
.Cells(L, 3) = ListBox1.List(i, 1)
.Cells(L, 4) = ListBox1.List(i, 3)
End If
Next
ActiveWorkbook.Save
End With
Application.DisplayAlerts = 0
'ActiveWorkbook.Close False
Application.DisplayAlerts = 1
ListBox1.MultiSelect = 0: ListBox1.MultiSelect = 1
End Sub
Sub ChargementListBox1()
'nettoyage
ListBox1.Clear
With ListBox1
'source des données sur le feuille
.RowSource = "D19:G235"
'affichage entête colonne
.ColumnHeads = False 'False 'où true
'nombre de colonne
.ColumnCount = 5
'largeur de la colonne
.ColumnWidths = "150;54;50;50;50"
End With
End Sub
'Private Sub CommandButton1_Click()
'copie les lignes selectionnées dans la colonne G
' Dim i As Integer
'Dim rg As Range
'Dim Fichier As Workbook
'Dim Chemin As String
'Call hautpage
' Chemin = commande.CBlistefournisseurs
'Application.ScreenUpdating = False
' On Error Resume Next
' Set Fichier = Workbooks.Open("C:\Facturation\base\fournisseurs\" & Chemin)
'With Workbooks(Chemin)
'on boucle sur tous les éléments du Listview
'For i = 1 To commande.ListBox1.ListCount 'commande.LVchoixarticles.ListItems.Count
'et on copie uniquement les items sélectionnées
' If ListBox1.Selected(i) = True Then .Sheets(1).Range("B65536").End(xlUp).Offset(1, 0) = ListBox1.List(i, 0)
' If ListBox1.Selected(i) = True Then .Sheets(1).Range("C65536").End(xlUp).Offset(0, 1) = ListBox1.List(i, 2)
' If ListBox1.Selected(i) = True Then .Sheets(1).Range("D65536").End(xlUp).Offset(0, 2) = ListBox1.List(i, 4)
'Next i
' .Close (1)
' End With
' Application.ScreenUpdating = True
'End Sub
Private Sub UserForm_Activate()
'activation du chargement de la listbox
Call ChargementListBox1
End Sub
Private Sub UserForm_Initialize()
Dim fournisseur As Variant, i As Integer
fournisseur = Array("Rouenel", "Rexel", "Tanguy", "Leadermat", _
"Queguiner", "Pointp", "Dispano", "Cedeo", "Kerbrat", "Qama", _
"Foussier", "Wurth")
For i = 0 To UBound(fournisseur)
CBlistefournisseurs.AddItem fournisseur(i)
Next i
'CBlistefournisseurs.ListIndex = 0
End Sub