title: How do I Close a already open cmd Window in vba?
body: <p>I'm new to programming with vba and I found this funtion in an old forum.
  I would like to add the option that at the end the cmd window be closed, for learning purposes.
  This is the Function where the cmd window is open. Running the command the result is save as a string. </p>
  
  <pre><code>Public Function ShellRun(sCmd As String) As String
  
  Dim oShell As Object
  Set oShell = CreateObject("WScript.Shell")
  
  
  Dim oExec As Object
  Dim oOutput As Object
  Set oExec = oShell.Exec(sCmd)
  Set oOutput = oExec.StdOut
  
  Dim s As String
  Dim sLine As String
  While Not oOutput.AtEndOfStream
      sLine = oOutput.ReadLine
      If sLine &lt;&gt; "" Then s = s &amp; sLine &amp; vbCrLf
  Wend
  
  ShellRun = s
  
  End Function
  </code></pre>