title: Excel: Specify table columns in .csv export macro
body: <p>I have a workbook with several worksheets that each contain an inventory list. Within that workbook I have another "Generate Order" worksheet that contains a table, which I've set up to consolidate the data from the other sheets. I would like a button on that sheet called "Export Order," which would export the contents of the <code>generateOrder</code> table as a .csv file.</p>
  
  <p>The catch is, in order to upload the order to the vendor's system, the .csv file must only contain the item number and the quantity, set up as "number,quantity" with each item on its own line.</p>
  
  <p>Currently I have this macro set up:</p>
  
  <pre><code>Sub export_button()
  
      Dim tbl As ListObject
      Dim csvFilePath As String
      Dim fNum As Integer
      Dim tblArr
      Dim rowArr
      Dim csvVal
  
      Set tbl = Worksheets("Generate Order").ListObjects("generateOrder")
      csvFilePath = "C:\Users\username\Desktop\order.csv"
      tblArr = tbl.DataBodyRange.Value
  
      fNum = FreeFile()
      Open csvFilePath For Output As #fNum
      For i = 1 To UBound(tblArr)
          rowArr = Application.Index(tblArr, i, 0)
          csvVal = VBA.Join(rowArr, ",")
          Print #1, csvVal
      Next
      Close #fNum
      Set tblArr = Nothing
      Set rowArr = Nothing
      Set csvVal = Nothing
  
  End Sub
  </code></pre>
  
  <p>Through a lot of Googling I've managed to get it working so that it does export the contents of <code>generateOrder</code> and save it as a .csv, but I'm trying to figure out the following modifications:</p>
  
  <ul>
  <li>I would like to export only the two columns named <code>PUBLISHER ITEM #</code>,<code>REORDER QTY</code> (in that order). If it matters, there's a line break between PUBLISHER and ITEM in the first column header.</li>
  <li>I would like the file to be named <code>value in cell C3</code>-order-<code>current date</code>.csv</li>
  <li>If they don't already exist, I'd like the macro to create a subfolder called "Orders" within the same folder where the workbook is located, and then create a subfolder inside Orders named <code>value in cell C3</code>, and then save the file there (instead of to the Desktop as it currently does).</li>
  </ul>
  
  <p>I need to figure out all of that but if you can at least help me figure out how to get only the two columns, I can try figuring out how to save it the way I want later. Many thanks!</p>