VBA code to convert excel to csv

Home/VBA/VBA code to convert excel to csv

We can use VBA to convert and Save the Excel File as CSV file. This example macro will help us to know how to convert Excel Worksheet into a CSV Comma delimited text file. This can be used in Excel 2003,2007,2010,2013.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

vba code to convert excel to csv- Syntax

Here is the example Excel VBA Syntax to convert the Excel to CSV.

Workbook.SaveAs fileName:="filepath to save the csv file", FileFormat:=xlCSV, CreateBackup:=False

VBA code to Convert and Save the Excel to CSV – Example

Here is the example macro to convert the Excel worksheet to CSV file.

'vba code to convert excel to csv
Sub vba_code_to_convert_excel_to_csv()
Set wb = Workbooks.Open("C:\temp\testwb.xlsx")
wb.SaveAs fileName:="C:\temp\testC.csv", FileFormat:=xlCSV, CreateBackup:=False
End Sub

This macro will open an existing Excel workbook from the C drive and Convert the file into CSV and Save the file with .CSV extension in the specified Folder. We are using Workbook Open method to open a file. SaveAs method to Save the file into destination folder. This example will be help full, if you wan to convert all excel files in a directory into CSV file.

VBA code to Convert and Save the Excel to CSV – Instructions

Please follow the below step by step instructions to test this Example VBA Macro codes:

  • Step 1: Open a New Excel workbook
  • Step 2: Press Alt+F11 – This will open the VBA Editor (alternatively, you can open it from Developer Tab in Excel Ribbon)
  • Step 3: Insert a code module from then insert menu of the VBE
  • Step 4: Copy the above code and paste in the code module which have inserted in the above step
  • Step 5: Change the Workbook name in the code as per your example folder and also change the destination file path as per your requirement
  • Step 6: Now press F5 to execute the code or F8 to debug the Macro to check it

Related Resource External VBA Reference
Excel VBA Reference Project Management Reference
VBA Reference:
Excel Reference:
By |January 20th, 2015|VBA|0 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

Leave A Comment

Related pages

vba rtrimvba guidemerge sheets excelvbscript to copy files from one folder to anothervba excel delete columnsexcel how to insert a rowexcel vba macrovba backcolorprograming excelmatch function on excelvb basic codesunprotect spreadsheetexcel formula cell coloursort macro excelactiveworkbook saveasexcel templates daily plannerexcel vba chartbasic macros in excelcopy entire excel sheethow to create dynamic charts in excelunlock excel without passwordexcel vba click buttonexcel vba trimexcel 2007 chart templatesproject dashboard templatehow to remove password from protected excel sheetinteractive excel dashboardsvlookup vba excelif statement in vbaexcel pivot tables advancedexcel vba programsexcel vba dim arrayexcel function offsethow to use pivot table in excel 2010 with examplenumber of rows and columns in ms excelhow to write macro in excelvba userform controlsadvanced excel shortcut keysvba excel gotomsgbox function in vbaccess database vbavba inputbox typeexcel spreadsheets for beginnersdml ddlhow to make radio buttons in excelvba excel cellvba formulasexcel combo box vbavlookup table in excelrange lookup excelhow to delete columns in excelaccess vba filesystemobjectvba xlupbutton macro excelhlookup in excel examplevba filedialogexcel vba insert rowsvba formvb command buttonexcel macro enabled workbookvba range sortformula to calculate difference between two datesexcel formulas examplesas coding basicssql basics interview questions and answers pdfcreate check box in excelinterview question answer for freshermerge to cells in excelcopy excel workbookdata mining viva questions and answershow to remove all macros from excel fileselect statement vbaexcel formula example sheetkeystrokes in excelhow to hyperlink excel sheetschange columns to rows in excelvba lookup functionexcel userform examplesaccess vba excelvlookup in excel formulausedrange excelprotect worksheet vbaexcel formulas to find duplicates