title: Using Excel VBA to run a CMD command
body: <p>I would like to use Excel VBA to run a CMD command.</p>
  
  <p>The basic cmd command is:</p>
  
  <pre><code>"C:\Program Files\example program.exe" -w C:\Program files\outputfile.file "dir1" "dir2" "dir n+1"
  </code></pre>
  
  <p>The first part is the location of the program that will merge the files together.
  The second part is the file location of the outputted merged files.
  And the "dir1".... is the files that will be merged together.</p>
  
  <p>I have code that lists the files to be merged but struggling to get the CMD code to get it so it does what I want as mentioned above. I have tried the following:</p>
  
  <pre><code>   Sub RunCMD()
  
          Dim wsh As Object
          Set wsh = VBA.CreateObject("WScript.Shell")
          Dim waitOnReturn As Boolean: waitOnReturn = True
          Dim windowStyle As Integer: windowStyle = 1
          Dim locationofprogram as string
         'dir of program that will do the merge
          Dim outputfolder as string
         'dir of where the merged file will go
          Dim listoffiles as string
         'list of files to be merged
  
          wsh.Run "cmd.exe /S /C locationofprogram &amp; " " &amp; "-w" &amp; " " &amp; outputfolder &amp; " " &amp; listoffiles, windowStyle, waitOnReturn
  
      End Sub
  </code></pre>
  
  <p>Thanks for the help!</p>