Organigramme automatique
Bonjour à tous,
Je viens vers vous car je suis officiellement une bille en VBA ( manque de temps pour finir de me former)
J'ai besoin de créer des organigrammes automatiques. Après quelques recherches j'ai trouvé le code suivant (Merci Jacques Boigontier) :
Dim colonne, débutOrg, f, forga, inth, intv, Tbl(), n
Sub DessineOrgaH()
Set f = Sheets("OrgaBD")
Set forga = Sheets("orgaDessin")
Tbl = f.Range("A2:D" & f.[A65000].End(xlUp).Row).Value
n = UBound(Tbl)
For Each s In forga.Shapes
If s.Type = 17 Or s.Type = 1 Then s.Delete
Next
inth = 70
intv = 60
colonne = 0
Set débutOrg = forga.Range("c4")
créeShape Tbl(1, 1), 1, Tbl(1, 4), f.Cells(2, 1).Interior.Color
End Sub
Sub créeShape(parent, niv, Attribut, coul) ' procédure récursive
hauteurshape = 45
largeurshape = 70
colonne = colonne + 1
forga.Shapes.AddShape(msoShapeFlowchartAlternateProcess, 10, 10, largeurshape, hauteurshape).Name = parent
forga.Shapes(parent).Line.ForeColor.SchemeColor = 1
txt = parent & vbLf & Attribut
With forga.Shapes(parent)
.TextFrame.Characters.Text = txt
.TextFrame.Characters(Start:=1, Length:=1000).Font.Size = 8
.TextFrame.Characters(Start:=1, Length:=1000).Font.ColorIndex = 0
.TextFrame.Characters(Start:=1, Length:=Len(parent)).Font.Bold = True
.Fill.ForeColor.RGB = coul
.TextFrame.Characters(Start:=1, Length:=Len(parent)).Font.Color = vbRed
End With
forga.Shapes(parent).Left = débutOrg.Left + inth * colonne
forga.Shapes(parent).Top = débutOrg.Top + intv * (niv - 1)
For i = 1 To n
If Tbl(i, 1) = parent And niv > 1 Then
Shapepère = Tbl(i, 2)
forga.Shapes.AddConnector(msoConnectorElbow, 100, 100, 100, 100).Name = parent & "c"
forga.Shapes(parent & "c").Line.ForeColor.SchemeColor = 22
forga.Shapes(parent & "c").ConnectorFormat.BeginConnect forga.Shapes(Shapepère), 3
forga.Shapes(parent & "c").ConnectorFormat.EndConnect forga.Shapes(parent), 1
End If
If Tbl(i, 2) = parent Then créeShape Tbl(i, 1), niv + 1, Tbl(i, 3), f.Cells(i + 1, 1).Interior.Color
Next i
End SubCe code est parfait, fonctionne (qui en doute quand on parle de Jacques) mais j'aimerais rajouter une colonne ou deux à la macro pour que dans l'organigramme des lignes supplémentaires apparaissent. Et c'est la que je n'y arrive pas…
A chaque fois que je modifie le code soit la macro ne fonctionne plus, soit les info n'apparaissent pas ou sont "écrasées" dans la bulle de l'organigramme.
J'en appel donc à votre aide !
Merci d'avance à ceux qui prendrons le temps de me lire !
En PJ le fichier avec les colonnes à rajouter ^.^
C'est bon !
Solution trouvé !
Dim colonne, débutOrg, f, forga, inth, intv, Tbl(), n
Sub DessineOrgaH()
Set f = Sheets("OrgaBD")
Set forga = Sheets("orgaDessin")
Tbl = f.Range("A2:F" & f.[A65000].End(xlUp).Row).Value
n = UBound(Tbl)
For Each s In forga.Shapes
If s.Type = 17 Or s.Type = 1 Then s.Delete
Next
inth = 100 '70
intv = 100 '60
colonne = 0
Set débutOrg = forga.Range("c4")
créeShape Tbl(1, 1), 1, Tbl(1, 3), Tbl(1, 4), Tbl(1, 5), Tbl(1, 6), f.Cells(2, 1).Interior.Color
End Sub
Sub créeShape(parent, niv, Attribut, Comp, Evo, Avis, coul) ' procédure récursive
hauteurshape = 60 '45
largeurshape = 100 '70
colonne = colonne + 1
forga.Shapes.AddShape(msoShapeFlowchartAlternateProcess, 10, 10, largeurshape, hauteurshape).Name = parent
forga.Shapes(parent).Line.ForeColor.SchemeColor = 1
txt = parent & vbLf & Attribut & vbLf & Comp & vbLf & Evo & vbLf & Avis
With forga.Shapes(parent)
.TextFrame.Characters.Text = txt
.TextFrame.Characters(Start:=1, Length:=1000).Font.Size = 8
.TextFrame.Characters(Start:=1, Length:=1000).Font.ColorIndex = 0
.TextFrame.Characters(Start:=1, Length:=Len(parent)).Font.Bold = True
.Fill.ForeColor.RGB = coul
.TextFrame.Characters(Start:=1, Length:=Len(parent)).Font.Color = vbBlue
End With
forga.Shapes(parent).Left = débutOrg.Left + inth * colonne
forga.Shapes(parent).Top = débutOrg.Top + intv * (niv - 1)
For i = 1 To n
If Tbl(i, 1) = parent And niv > 1 Then
Shapepère = Tbl(i, 2)
forga.Shapes.AddConnector(msoConnectorElbow, 100, 100, 100, 100).Name = parent & "c"
forga.Shapes(parent & "c").Line.ForeColor.SchemeColor = 22
forga.Shapes(parent & "c").ConnectorFormat.BeginConnect forga.Shapes(Shapepère), 3
forga.Shapes(parent & "c").ConnectorFormat.EndConnect forga.Shapes(parent), 1
End If
If Tbl(i, 2) = parent Then créeShape Tbl(i, 1), niv + 1, Tbl(i, 3), "Compétence: " & Tbl(1, 4), "Evolution: " & Tbl(1, 5), "Avis manager: " & Tbl(1, 6), f.Cells(i + 1, 1).Interior.Color
Next i
End SubA plus sur le forum