How to convert xls to CSV on

Updated July 20, 2017

Microsoft Excel is a spreadsheet application that is part of the Microsoft Office suite. Visual Basic.NET is a Microsoft programming language that’s relatively easy to learn and use. A Comma-Separated Value (CSV) file is a plain text file that can be easily read by other applications. A CSV file is also used to save hard drive space since it’s much smaller in size than a normal XLS file. In a few simple steps, you can convert XLS files to CSV files using VB.NET.

Start “Microsoft Visual Basic 2008 Express." Select the “File” menu, then click “New Project…” Click “Windows Forms Application” under “Visual Studio installed templates.” Select “OK."

Press “Ctrl," "Alt," and "X” to open the “Toolbox." Double-click “Button” under “Common Controls” to add a new button to “Form 1."

Click “Project,” then select “Add Reference." Click “COM," select “Microsoft Excel 12.0 Object Library” and click “OK."

Double-click “Button 1” to open the “Form1.vb” module. Type the following at the very top of “Form1.vb” to add a reference:

Imports Microsoft.Office.Interop

Type the following to declare your variables inside "Sub Button1_Click":

Dim excel Application As New Excel.Application Dim excelWrkBook As Excel.Workbook

Type “excelApplication.Visible = False” to hide Excel. Type “excelApplication.DisplayAlerts = False” to disable displaying message alerts.

Type the following to open your "XLS" workbook and save it as "CSV":

excelWrkBook = excelApplication.Workbooks.Open("C:\myWorkbook.xls") excelWrkBook.SaveAs(Filename:="c:\myWorkbookCSV.csv", _ FileFormat:=Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV)

When you run your program and click ”Button 1,” this code will execute to convert your file.

Type the following to close and quit your application:

excelWrkBook.Close() excelApplication.DisplayAlerts = True excelApplication.Quit()

Press "F5" to execute your program. Click "Button1."

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jaime Avelar is a professional writer whose programming articles appear on various websites. He has been a software programmer since 2000. Avelar holds a Master of Science in information systems from the University of Texas at Arlington.