user1175790
user1175790

Reputation:

Export a file in csv format programmatically with microsoft excel

I need to export a file in csv format programmatically. I added the following function that I call when the user clicks on a button:

Public Sub CreateCVS()
    ActiveWorkbook.SaveAs Filename:="filename.csv", _
        FileFormat:=xlCSV, CreateBackup:=False
End Sub

the problem is that I do not want to saveAs my file I want to export it in csv format but the spreadsheet should still be a xlsm file.

Is it possible

Upvotes: 0

Views: 1412

Answers (1)

nutsch
nutsch

Reputation: 5962

Just export your worksheet first

Public Sub CreateCVS()
    activesheet.copy
    ActiveWorkbook.SaveAs Filename:="filename.csv", _
        FileFormat:=xlCSV, CreateBackup:=False
    activeworkbook.close false
End Sub

Upvotes: 1

Related Questions