title: VBA Macro to combine CSV Files with Command Line copy function
body: <p>I've written a macro which enables files within a selected folder to be combined using the command shell. The reason I'm using the command prompt is that the files are large and take some time to open. </p>
  
  <p>The problem is that when I pick a folder that contains a space (i.e. J:\Network Accrual\Invoices) the macro fails. I've attempted to follow other suggestions that include 4 quotations ("""" &amp; path &amp; """"), however this does not seem to for the operation I have set - "cmd.exe /C copy  J:\TEST*csv J:\TEST\Combined.csv".</p>
  
  <p>Here is the code:</p>
  
  <pre><code>Private Sub COMBINE_FILES()
  
  Dim FldrPicker As FileDialog
  Dim myPath As String
  
  'Retrieve Target Folder Path From User
  Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
  
  With FldrPicker
    .Title = "Select A Target Folder"
    .AllowMultiSelect = False
      If .Show &lt;&gt; -1 Then GoTo NextCode
      myPath = .SelectedItems(1) &amp; "\"
  End With
  
  'In Case of Cancel
  NextCode:
    myPath = myPath
    If myPath = "" Then GoTo ResetSettings
  
  'Display path
  MsgBox myPath
  
   'Combine files in Command Line
    Dim RET As Variant
    RET = Shell("cmd.exe /C copy  " &amp; myPath &amp; "*csv " &amp; myPath &amp; "Combine.csv", 0)
  
  ResetSettings:
  'Reset Macro Optimization Settings
      Application.EnableEvents = True
      Application.Calculation = xlCalculationAutomatic
      Application.ScreenUpdating = True
  
  End Sub
  </code></pre>