comment remplir un listview sur excel a partir d'une table access
Version imprimable
comment remplir un listview sur excel a partir d'une table access
Le plus simple c'est de faire une requete via power query, ca va te faire un tableau structuré, et en suite tu mets cette fonction sur ton userform a chaque fois que tu veux faire une MAJ de ce listview (exemple: initialisation de l'usf)
Il faut que tu donne le nom de ta listview ainsi que la feuille qui contient ton tableau structuré.Code:
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 Function listviewrefresh(mylistView As listView, sht As Worksheet) As Boolean Dim myCol As ListColumn Dim myTab As ListObject Dim nbcol As Integer Dim i As Integer Dim j As Integer nbcol = sht.ListObjects(1).ListColumns.count mylistView.ListItems.Clear mylistView.ColumnHeaders.Clear Set myTab = sht.ListObjects(1) listviewrefresh = True If sht.ListObjects(1).ListRows.count = 0 Then listviewrefresh = False Exit Function End If For i = 1 To myTab.ListColumns.count Set myCol = myTab.ListColumns(i) mylistView.ColumnHeaders.Add , , myCol.Name, myCol.DataBodyRange.Width Next i For i = 1 To myTab.ListRows.count mylistView.ListItems.Add , , myTab.DataBodyRange(i, 1) For j = 2 To nbcol mylistView.ListItems(i).ListSubItems.Add , , myTab.DataBodyRange(i, j) Next j Next i mylistView.View = lvwReport mylistView.FullRowSelect = True mylistView.LabelEdit = lvwManual mylistView.Gridlines = True End Function