Tuesday, July 29, 2008

Excel to csv Vb

Dim fso
Set fso = CreateObject("scripting.filesystemobject")
Dim fldr
Dim extn
Dim flename
Dim oxlApp
Set oxlApp =CreateObject("Excel.Application")
Dim oxlWB
Set fldr = fso.GetFolder("Folder path")
oxlApp.Visible = True
For Each flename In fldr.Files
extn = Right(flename.Name, 4)
If extn = ".xls" Then
Set oxlWB = oxlApp.Workbooks.Open(flename)
for j = 1 to oxlWB.Sheets.Count
oxlWB.Sheets(j).Activate
Dim Name
Name = oxlWB.Sheets(j).Name
Name = "Folder Path" & Name & ".csv"
oxlWB.SaveAs Name, -4158
Next
oxlWB.Close False
End If
Next
oxlApp.Quit
Set oxlApp = Nothing