title: Making org chart in PowerPoint basing on Excel
body: <p>I am trying to write a project that will create org chart in PowerPoint basing on table in Excel. So, I have a simple table in Excel with two columns: Employee and Reports_to. Something like that </p>
  
  <pre><code>Employee    Reports_to
  Joe         Eva
  Jane        Ann
  John        Eva
  Eva         Olaf
  Ann         Olaf
  Bill        Ann
  Gilbert     Ann
  Olaf    
  </code></pre>
  
  <p>Then I have simple function to find all subordinates for any boss: </p>
  
  <pre><code>Function GetMinions(sMaster As String) As Collection
  
  Dim rngEmp As Range, cl As Range
  Dim collMinions As New Collection
  
  With ThisWorkbook.Worksheets(1)
      Set rngEmp = Range(.Range("A2"), .Range("A" &amp; .Rows.Count).End(xlUp))
  End With
  
  For Each cl In rngEmp
      If cl.Offset(, 1) = sMaster Then collMinions.Add cl.Value
  Next cl
  
  Set GetMinions = collMinions
  
  End Function
  </code></pre>
  
  <p>I also have code that is creating new PowerPoint presentation with one slide and one org chart in this slide. I delete all nodes in this org chart except of the root node. All of that works perfectly, so I don't paste the code. 
  And here is my working horse, the macro that build org chart from to to bottom.</p>
  
  <pre><code>Sub PopulateOrgChart(nd As Object, str As String)
  Dim Minions As Collection
  Dim hasMinions As New Collection
  Dim it As Object
  Dim childNd As Object
  Dim i As Integer
  
  Set Minions = GetMinions(str)
  For i = 1 To Minions.Count
      Set childNd = nd.Nodes.Add
      Debug.Print nd.Level &amp; "    " &amp; childNd.Level
      childNd.TextFrame2.TextRange.Text = Minions.item(i)
      If GetMinions(Minions.item(i)).Count &gt; 0 Then hasMinions.Add childNd
  Next i
  
      For i = 1 To hasMinions.Count
      PopulateOrgChart hasMinions(i), hasMinions(i).TextFrame2.TextRange.Text
  Next i
  End Sub
  </code></pre>
  
  <p>I am running this macro with arguments (smr is defined smartart object): </p>
  
  <pre><code>PopulateOrgChart smr.Nodes(1), "Olaf"
  </code></pre>
  
  <p>And the result is: </p>
  
  <p><a href="https://i.stack.imgur.com/sqTAo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sqTAo.png" alt="enter image description here"></a></p>
  
  <p>As you can see, Eva and Ann are both in right place as middle-rank managers, all others seems to be OK in third line except of Joe, which is placed just below the top manager. I have tried to figure out what is going on and placed this line after setting the child node:</p>
  
  <pre><code>Debug.Print nd.Level &amp; "    " &amp; childNd.Level
  </code></pre>
  
  <p>and my Immediate Window show the same story as my org chart:</p>
  
  <pre><code>1    2
  1    2
  2    2
  2    3
  2    3
  2    3
  2    3
  </code></pre>
  
  <p>when adding node for the first subordinate of Eva, it gives the child the same level as for the parent. I am quite confused, as the macro works as expected for all other employees. What I am doing wrong and how could I make Joe subordinate to Eva node, not to the root?</p>