Export Office Excel table to csv using a macro
There is no built-in Excel command or function that would do the kind of thing you want, but you can use VBA to program it.
The following code may be close to what you are looking for:
Sub ExportTable()
Dim wb As Workbook, wbNew As Workbook
Dim ws As Worksheet, wsNew As Worksheet
Dim wbNewName As String
Set wb = ThisWorkbook
Set ws = ActiveSheet
Set wbNew = Workbooks.Add
With wbNew
Set wsNew = wbNew.Sheets("Sheet1")
wbNewName = ws.ListObjects(1).Name
ws.ListObjects(1).Range.Copy
wsNew.Range("A1").PasteSpecial Paste:=xlPasteAll
.SaveAs Filename:=wb.Path & "\" & wbNewName & ".csv", _
FileFormat:=xlCSVMSDOS, CreateBackup:=False
End With
End Sub
The code assumes that you have one table in each worksheet. It creates a new workbook, copies the table into Sheet 1 of that workbook, and saves the workbook as a CSV file with the same name as the table.
Here's my version of chuff's answer for Excel 2013. It also disables the modal dialogs:
Sub ExportCSV()
Dim wb As Workbook, wbNew As Workbook
Dim ws As Worksheet, wsNew As Worksheet
Set wb = ThisWorkbook
Set ws = ActiveSheet
Set wbNew = Workbooks.Add
Application.DisplayAlerts = False
With wbNew
Set wsNew = wbNew.Sheets("Sheet1")
ws.Rows.Copy
wsNew.Paste
.SaveAs Filename:=ws.name & ".csv", FileFormat:=xlCSV, CreateBackup:=True
wsNew.Delete
End With
Windows(ws.name & ".csv").Activate
ActiveWindow.Close
Application.DisplayAlerts = True
End Sub