demyx999
demyx999

Reputation: 121

Error trying to save Excel worksheet as CSV via Excel VBA macro

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."

So a couple things:

Picture of error message

My excel VBA save-as-CSV macro:

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

Upvotes: 2

Views: 1565

Answers (1)

GMalc
GMalc

Reputation: 2628

Try this, you don't have to use Copy or Activate. If your code is in the workbook that you want to save as a workbook you can use ThisWorkbook. Kudos to @Variatus for identifying need for a path.

ThisWorkbook.Sheets("Sheet1").SaveAs ThisWorkbook.Path & "/" & "dummyfilename" & ".csv", FileFormat:=6

Upvotes: 0

Related Questions