title: Removing blank columns/rows in VBA as part of csv save
body: <p>I am using the following VBA code to save each individual sheet in a .xlsx workbook into a .csv file.</p>
  
  <p>Whilst the code is working well I would like to adapt the VBA code so blank columns &amp; rows are removed from the .csv files which are being created.</p>
  
  <p><strong>Existing VBA Code:</strong>   </p>
  
  <pre><code>Public Sub SaveWorksheetsAsCsv()
     Dim xWs As Worksheet
     Dim xDir As String
     Dim folder As FileDialog
     Set folder = Application.FileDialog(msoFileDialogFolderPicker)
     If folder.Show &lt;&gt; -1 Then Exit Sub
     xDir = folder.SelectedItems(1)
     For Each xWs In Application.ActiveWorkbook.Worksheets
        xWs.SaveAs xDir &amp; "\" &amp; xWs.Name, xlCSV
     Next
  End Sub
  </code></pre>
  
  <p>To remove blank rows &amp; columns I was able to get the below JavaScript working in a .hta application, but would like to integrate this same functionality into the above VBA code.</p>
  
  <pre><code>//Remove all blank rows
  
  for(var i = usedRng.Rows.Count; i &gt; 0; i--){
      if( xlApp.CountA(usedRng.Rows(i)) == 0 ) usedRng.Rows(i).Delete();
  }
  
  //Remove all blank columns
  
  for(var i = usedRng.Columns.Count; i &gt; 0; i--){
      if( xlApp.CountA(usedRng.Columns(i)) == 0 ) usedRng.Columns(i).Delete();
  }
  </code></pre>
  
  <p>How can I integrate this row/column removal code into VBA?</p>