title: Make Excel VBA wait until operation is finished
body: <p>I have made a macro in VBA to split PDF files into single pages.</p>
  
  <pre><code>Sub SplitFiles()
  
  'This needs PDFTK installed
  
  Dim fso As New FileSystemObject
  Dim fol As Folder
  Dim fil As File
  Dim i As Integer
  Dim command As String
  
  On Error Resume Next
  
  Set fol = fso.GetFolder("C:\Users\wanne\OneDrive\Documents\Bijberoep\Scans\Splitsen\")
  
  i = 1
  
  For Each fil In fol.Files
      command = ("C:\Program Files (x86)\PDFtk\bin\pdftk.exe " &amp; fil &amp; " burst output C:\Users\wanne\OneDrive\Documents\Bijberoep\Scans\Klaar\Klaar" &amp; i &amp; "-%d.pdf")
      Shell command
      i = i + 1
  Next fil
  
  Application.Wait (Now + TimeValue("0:00:05"))
  
  Kill "C:\Users\wanne\OneDrive\Documents\Bijberoep\Scans\Splitsen\*.pdf"
  Kill "C:\Users\wanne\OneDrive\Documents\Bijberoep\Scans\Klaar\*.txt"
  
  End Sub
  </code></pre>
  
  <p>The problem is that I had to give a timeout of 5 seconds, or else the files get deleted immediately, and no output is created.</p>
  
  <p>How can I make excel wait until all files are processed?</p>