title: Check a command window is closed
body: <p>Below is the code we use to run to check the Ping and Trace for our site address. We have a userform which we need to enter some details and when we hit run this will start running. So when we start running it will create a batch file which (opens a command window) will first the ping and then the Trace. So the ping will finish within a 5 sec but the trace root will take some time and this is not a fixed time. Once both finish running the command window closes automatically. How do the macro knows the command window is closed so that we can enable a button in our userform to submit the report. We need a code to check whether the command window is closed and then it can go to the line &quot;cmdFinishSlow.Enabled = True&quot;</p>
  <p>Please can anyone help me with this? Also this will not work in a 64bit Excel, is there any solution for that too?</p>
  <pre><code>    Dim address, NetStatAN, PingTextFile, BatchFile, TraceTextFile As String
      Dim row As Integer
      Dim inputline As String
      Dim lineitems() As String
      Dim Filepath As String
      
      Dim MyFSO As FileSystemObject
      Set MyFSO = New FileSystemObject
      
      Filepath = &quot;C:\Users\&quot; &amp; Environ(&quot;Username&quot;) &amp; &quot;\Desktop\&quot;
      BatchFile = &quot;batchfile.bat&quot;
      PingTextFile = &quot;PingSite.txt&quot;
      TraceTextFile = &quot;TraceSite.txt&quot;
      
      'Call Shell(&quot;explorer.exe&quot; &amp; &quot; &quot; &amp; Filepath, vbNormalFocus)
      
      On Error Resume Next
      Kill (Filepath &amp; BatchFile)
      Kill (Filepath &amp; PingTextFile)
      Kill (Filepath &amp; TraceTextFile)
      On Error GoTo 0
  
      row = 1
      address = Sheets(&quot;Slowness Issue&quot;).Range(&quot;C9&quot;).Value
  
      Do Until Trim(address) = &quot;&quot;
          Open Filepath &amp; BatchFile For Output As #1
              Print #1, &quot;ping &quot; &amp; address &amp; &quot; &gt;&gt;&quot;; Filepath &amp; PingTextFile
              Print #1, &quot;tracert -d &quot; &amp; address &amp; &quot; &gt;&gt;&quot;; Filepath &amp; TraceTextFile
          Close #1
  
          Call Shell(Filepath &amp; BatchFile)
          
          Application.Wait DateAdd(&quot;s&quot;, 5, Now) ' wait for 10 seconds      
          Open Filepath &amp; PingTextFile For Input As #1
  
          Line Input #1, inputline       
          If Left(inputline, 10) = &quot;Reply from&quot; Then
              lineitems() = Split(inputline, &quot; &quot;)
              Cells(row, 2) = lineitems(2)
              Cells(row, 3) = Now
          End If
  
          row = row + 1
          address = Cells(row, 1)
  
      Loop
      
  ' Here I need to check the command window is closed or not
  
  cmdFinishSlow.Enabled = True
  cmdRunSlow.Enabled = False
  </code></pre>