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
| Private Sub Create_ListView_Dynamic()
'Declare Variable Names
Dim oLv As ListView
Dim Wsheet As Worksheet
'Create ListView in WorkSheet
Set Wsheet = ThisWorkbook.Sheets(2)
Set oLv = Wsheet.OLEObjects.Add(ClassType:="MSComctlLib.ListViewCtrl.2", _
Link:=False, DisplayAsIcon:=False, Left:=100, Top:=100, Width:=300, Height:=100).Object
'Give ListView Control a Name
oLv.Name = "ListCust"
'Assign Value to Other Properties
With oLv
.Left = 20
.Top = 20
.Height = 100
.Width = 492
.Visible = True
.View = lvwReport
End With
End Sub
Private Sub Access_ListView_Add_Data()
'Declare Variable Names
Dim i As Integer
Dim oLv As ListView
Dim oLi As ListItem
Dim Wsheet As Worksheet
'Get ListView in WorkSheet to an Object
Set Wsheet = ThisWorkbook.Sheets(2)
Set oLv = Wsheet.OLEObjects("ListCust").Object
'Clear Header & Add Column Headers
oLv.ColumnHeaders.Clear
With oLv
.ColumnHeaders.Add 1, "Réunions", "Réunions"
.ColumnHeaders.Add 2, , "1ère"
.ColumnHeaders.Add 3, , "2ème"
.ColumnHeaders.Add 4, , "3ème"
.ColumnHeaders.Add 5, , "4ème"
.ColumnHeaders.Add 6, , "5ème"
.ColumnHeaders.Add 7, , "6ème"
.ColumnHeaders.Add 8, , "7ème"
.ColumnHeaders.Add 9, , "8ème"
.ColumnHeaders.Add 10, , "9ème"
.View = lvwReport
End With
'Add Data to ListView
oLv.ListItems.Clear
Set oLi = oLv.ListItems.Add(1, , "R1")
For i = 1 To 9
oLi.SubItems(i) = "R1C" & i
Next i
Set oLi = oLv.ListItems.Add(2, , "R2")
For i = 1 To 9
oLi.SubItems(i) = "R2C" & i
Next i
Set oLi = oLv.ListItems.Add(3, , "R2")
For i = 1 To 9
oLi.SubItems(i) = "R3C" & i
Next i
Set oLi = oLv.ListItems.Add(4, , "R2")
For i = 1 To 9
oLi.SubItems(i) = "R4C" & i
Next i
'In Some Systems, ListView Value will not be Visible when you just run above code.
'Execute below code to get the values visible & align properly
oLv.Visible = False
oLv.Visible = True
ActiveSheet.Shapes("ListCust").Select
With Selection
.Placement = xlFreeFloating
.PrintObject = True
End With
ActiveWindow.SmallScroll Down:=-24
ActiveWindow.SmallScroll Up:=24
End Sub |
Partager