Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Export all worksheets in a known Excel file to csv's programatically using a VBS script?
- Dim source As Workbook
- Set source = Application.Workbooks.Open(WScript.Arguments.Item(0), ReadOnly:=True)
- For Each sheet In source.Sheets
- .SaveAs Filename:= WScript.Arguments.Item(1) & Source.Sheets.Name, FileFormat:=xlCSV
- Next sheet
- wb.Close
- Dim strFilename
- Dim objFSO
- Set objFSO = CreateObject("scripting.filesystemobject")
- strFilename = "C:temptest.xlsx"
- If objFSO.fileexists(strFilename) Then
- Call Writefile(strFilename)
- Else
- wscript.echo "no such file!"
- End If
- Set objFSO = Nothing
- Sub Writefile(ByVal strFilename)
- Dim objExcel
- Dim objWB
- Dim objws
- Set objExcel = CreateObject("Excel.Application")
- Set objWB = objExcel.Workbooks.Open(strFilename)
- For Each objws In objWB.Sheets
- objws.Copy
- objExcel.ActiveWorkbook.SaveAs objWB.Path & "" & objws.Name & ".csv", 6
- objExcel.ActiveWorkbook.Close False
- Next
- objWB.Close False
- objExcel.Quit
- Set objExcel = Nothing
- End Sub
- -------------------------------
- SELECT * FROM Demo
- -------------------------------
- |F1|F2 |F3 |F4 |
- | 1|1.1|12/10/2011|text elm 1|
- | 2|2.2|12/11/2011|text elm 2|
- | 3|4.4|12/12/2011|text elm 3|
- -------------------------------
- Provider=MSDASQL.1;Extended Properties="DBQ=<FullPathToYourXls>;Driver={Microsoft
- Excel Driver (*.xls)};
- SELECT * INTO [Demo.csv] IN '<PathToYourCsvFolder>' 'Text;' FROM Demo
- type ..dataExcelCsv2Demo.csv
- "F1";"F2";"F3";"F4"
- 1;1,10;10.12.2011 00:00:00;"text elm 1"
- 2;2,20;11.12.2011 00:00:00;"text elm 2"
- 3;4,40;12.12.2011 00:00:00;"text elm 3"
- [Demo.csv]
- ColNameHeader=True
- CharacterSet=1252
- Format=Delimited(;)
- Col1=F1 Integer
- Col2=F2 Float
- Col3=F3 Date
- Col4=F4 Char Width 50
Add Comment
Please, Sign In to add comment