title: Error trying to save Excel worksheet as CSV via Excel VBA macro
body: <p>Using Excel 2010 on Windows 7. I have a VBA macro that saves the first worksheet of an excel workbook (.xlsm) into a CSV file. This had mostly worked in the past. Recently, I get error messages per the picture below, which state "Run-time error '1004': Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space."</p>
  
  <p>So a couple things:</p>
  
  <ul>
  <li>A common suggested solution from my Google searching is to set the file's location as a Trusted Location. This did not work.</li>
  <li>I have enough disk space. That can't be the issue.</li>
  <li>I'm not sure exactly what is meant by "available memory," but if it in any way refers to the Physical Memory figure listed in Windows Task Manager, that figure is 75%. The ultimate CSV file itself tends to be about 1,500KB.</li>
  <li>I am always able to save this worksheet as a CSV manually without encountering any error messages, but when I do it via this VBA macro, I get the error message.</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/D51JA.png" rel="nofollow noreferrer">Picture of error message</a></p>
  
  <p>My excel VBA save-as-CSV macro:</p>
  
  <pre><code>Sub saveAsCSV()
  Application.DisplayAlerts = False
  
  ThisWorkbook.Sheets("Sheet1").Copy
  ActiveWorkbook.SaveAs Filename:="dummyfilename.csv", FileFormat:=xlCSV, CreateBackup:=True
  ActiveWorkbook.Close
  
  Application.DisplayAlerts = True
  End Sub
  </code></pre>