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
| Option Explicit
Public Sub AfficherListeComposant()
Dim Ctrl1 As CommandButton
Dim Ctrl2 As CommandButton
Dim Ctrl3 As Variant
Dim NomUSF As String
Dim Code1 As String
Dim Code2 As String
Dim NombreLignesIni As Long
Dim NombreLignesFin As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim USF As Variant
Dim USF2 As Variant
Dim fichier As String
Dim mp As Integer
Dim NombreComposantsString As String
Dim NombreActionneursString As String
Dim NombreComposants As Integer
Dim NombreActionneurs As Integer
Dim NomActionneur As String
Dim nomComposant As String
Dim top As Integer
Dim Code As String
Dim Poubelle As Variant
Dim oneControl As Variant
Dim llll As Variant
Dim NombreBoucles As Long
NombreBoucles = 2
Set USF = ActiveDocument.VBProject.VBComponents("ListeComposant")
top = 48
fichier = "blablabla\essai.txt"
NombreActionneursString = LitDansFichierIni("Actuators", "Actuator_Length", fichier, "")
NombreActionneurs = CInt(NombreActionneursString)
NombreLignesIni = ActiveDocument.VBProject.VBComponents("ListeComposant").CodeModule.CountOfLines
For i = 0 To NombreBoucles - 1
Set Ctrl1 = USF.Designer.Controls.Add("Forms.CommandButton.1")
Set Ctrl2 = USF.Designer.Controls.Add("Forms.CommandButton.1")
With Ctrl1
.Name = "ToutCocherActionneur" & CStr(i)
.Caption = "Tout cocher"
.top = 48 + 6
.Left = 12 + i * 160
.height = 24
.width = 72
End With
With Ctrl2
.Name = "ToutDecocherActionneur" & CStr(i)
.Caption = "Tout décocher"
.top = 48 + 30
.Left = 12 + i * 160
.height = 24
.width = 72
End With
Code1 = "Private Sub " & Ctrl1.Name & "_Click()" & vbCrLf
Code1 = Code1 & "Dim i as integer" & vbCrLf
Code1 = Code1 & "for i = 0 To NombreComposants - 1" & vbCrLf
Code1 = Code1 & " Me.Controls (""Actionneur"" & Cstr(" & CStr(i) & ") & ""Composant"" & Cstr(i)).Value = True" & vbCrLf
Code1 = Code1 & "Next" & vbCrLf
Code1 = Code1 & "End Sub"
Code2 = "Private Sub " & Ctrl2.Name & "_Click()" & vbCrLf
Code2 = Code2 & "Dim i as integer" & vbCrLf
Code2 = Code2 & "for i = 0 To NombreComposants - 1" & vbCrLf
Code2 = Code2 & " Me.Controls (""Actionneur"" & Cstr(" & CStr(i) & ") & ""Composant"" & Cstr(i)).Value = False" & vbCrLf
Code2 = Code2 & "Next" & vbCrLf
Code2 = Code2 & "End Sub"
With ActiveDocument.VBProject.VBComponents("ListeComposant").CodeModule
.InsertLines NombreLignesIni + 1, Code1
.InsertLines NombreLignesIni + 1, Code2
End With
Next i
VBA.UserForms.Add(USF.Name).Show
For Each oneControl In USF.Designer.Controls
If oneControl.Name <> "Label3" And oneControl.Name <> "OK" And oneControl.Name <> "CadreComposantsAMarquer" Then
llll = oneControl.Name
USF.Designer.Controls.Remove (oneControl.Name)
End If
Next
NombreLignesFin = ActiveDocument.VBProject.VBComponents("ListeComposant").CodeModule.CountOfLines
With USF.CodeModule
.deleteLines NombreLignesIni + 1, NombreLignesFin - NombreLignesIni
End With
Set USF2 = ActiveDocument.VBProject.VBComponents("Entete")
VBA.UserForms.Add(USF2.Name).Show
End Sub |
Partager