Created
December 9, 2015 17:25
-
-
Save JamoCA/62666b5ef89ec54ef3c2 to your computer and use it in GitHub Desktop.
Visual Basic Script to convert CSV file to XLSX. (Excel is required to be installed.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'====================================== | |
'Visual Basic Script to convert CSV file to XLSX. (Excel is required to be installed.) | |
'http://stackoverflow.com/a/31606893/693068 | |
'Further customization ideas and information regarding permissions at: | |
'http://jeffkinzer.blogspot.com/2010/06/vbscript-to-convert-csv-to-xlsx.html | |
' | |
'FORMAT: CSCRIPT CSV_To_XLSX.vbs "c:\base\data.csv" | |
'(Note: CSCRIPT is required to run VBS file using the command line.) | |
'====================================== | |
Dim file, WB | |
With CreateObject("Excel.Application") | |
On Error Resume Next | |
For Each file In WScript.Arguments | |
Set WB = .Workbooks.Open(file) | |
WB.SaveAs Replace(WB.FullName, ".csv", ".xlsx"), 51 | |
WB.Close False | |
Next | |
.Quit | |
End With | |
WScript.Echo "Done!" |
Thanks for sharing this. This converted my files to .xlsx. Is there a way to incorporate VBS code inside VBA? I can do this task in VBA but my problem is that it's taking so long before the task to be completed. Mainly because of opening large files in Excel. When I use VBS for the same task, it's way faster than VBA. So, I'm thinking if it's possible to incorporate these two. I would also need to make some customization because the file name and file path is inside the workbook. Thanks.
Note: I know that VBS and VBA are somehow related but I only know the syntax of VBA.
Thank you for sharing. In case you dont have Excel installed you can use an online converter
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To change the sheet name:
WB.Sheets(1).Name = "Devharsh"
To run this script for all csv in directory: