Export active worksheet to CSV file : CSV « File Path « VBA / Excel / Access / Word






Export active worksheet to CSV file

 

Sub ExportActiveWorksheet()
  Dim oldname$, oldpath$, oldformat
  Application.DisplayAlerts = False  'avoid safetey alert
  With ActiveWorkbook
    oldname = .Name
    oldpath = .Path
    oldformat = .FileFormat
    .ActiveSheet.SaveAs _
      Filename:="c:\file.csv", FileFormat:=xlCSV
    .SaveAs Filename:=oldpath + "\" + oldname, FileFormat:=oldformat
  End With
  Application.DisplayAlerts = True
End Sub

 








Related examples in the same category

1.Query text file
2.Saves the active worksheet in the workbook named MyWorkbook.xls as a comma-delimited text file named test.csv:
3.Split demonstration
4.Brings up a dialog box that asks the user for a filename.
5.Create text file based database