title: Can you have a Excel Macro to auto-save a copy as CSV
body: <p>Loading an XLS file is a bit of a pain for a quick app we're throwing together (we know about how to do that but it's not worth the time especially in C++) so we're going to take the simple approach of have the user export a CSV copy. However to save them the trouble I wondered if we can have a macro which will automatically save a CSV version whenever they save the XLS(X) in Excel 2007?</p>
  
  <p><strong>Update:</strong>
  Following Timores' answer, I dug in a bit and came up with this:</p>
  
  <pre><code>Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
      Dim Sourcewb As Workbook
      Dim Destwb As Workbook
      Dim TempFileName As String
  
      With Application
          .ScreenUpdating = False
          .EnableEvents = False
      End With
  
      Set Sourcewb = ActiveWorkbook
      TempFileName = Sourcewb.FullName + ".csv"
  
      'Copy the sheet to a new workbook
      ActiveSheet.Copy
      Set Destwb = ActiveWorkbook
  
      'Save the new workbook and close it
      With Destwb
          .SaveAs Filename:=TempFileName, FileFormat:=xlCSV, ConflictResolution:=xlLocalSessionChanges
          .Close SaveChanges:=False
      End With
  
      With Application
          .ScreenUpdating = True
          .EnableEvents = True
      End With
  End Sub
  </code></pre>
  
  <p>This works except I can't make it force-save the CSV, rather than asking me if I want to overwrite, even after adding <code>ConflictResolution:=xlLocalSessionChanges</code></p>