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
| Private Sub UserForm_Initialize()
On Error GoTo ErrorHandler
Dim Col As Integer, Ligne As Integer
Dim NoeudMere As String
Dim NoeudFille As String
Dim texte As String
' Check if the "Direction" sheet exists
If Not SheetExists("Direction") Then
MsgBox "Sheet 'Direction' not found!"
Exit Sub
End If
With Sheets("Direction")
' Adding parent nodes from the first row of columns 1 to 5
For Col = 1 To 5
TreeViewAgent.Nodes.Add , , Replace(.Cells(1, Col).Value, " ", ""), .Cells(1, Col).Value
Next Col
' Adding child nodes under each parent node
For Col = 1 To 5
Ligne = 2
NoeudMere = Replace(.Cells(1, Col).Value, " ", "")
Do While .Cells(Ligne, Col) <> ""
NoeudFille = Replace(NoeudMere, " ", "") & "_" & Replace(.Cells(Ligne, Col).Value, " ", "")
texte = .Cells(Ligne, Col).Value
TreeViewAgent.Nodes.Add NoeudMere, tvwChild, NoeudFille, texte
Ligne = Ligne + 1
Loop
Next Col
End With
' Check if the "Base" sheet exists
If Not SheetExists("Base") Then
MsgBox "Sheet 'Base' not found!"
Exit Sub
End If
With Sheets("Base")
' Adding nodes for the "Base" sheet
Col = 29
Ligne = 2
Do While .Cells(Ligne, Col).Value <> ""
NoeudMere = Replace(.Cells(Ligne, Col).Value, " ", "") & "_" & Replace(.Cells(Ligne, Col - 26).Value, " ", "")
NoeudFille = .Cells(Ligne, 1).Value
texte = .Cells(Ligne, 2).Value
TreeViewAgent.Nodes.Add NoeudMere, tvwChild, NoeudFille, texte
Ligne = Ligne + 1
Loop
End With
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description & " -> " & NoeudMere
End Sub |
Partager