I'm trying to change an excel file to csv but the methods I've used so far have corrupted the file.
I've tried renaming the file and using saveas from excel.
Dim importsFileList As New ArrayList
Dim sFile As String
Dim extension As String
Dim newExtension As String
Dim file As IO.FileStream
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
sFile = Dir$("C:\Users\filePath" & "\*.*", vbDirectory)
Do Until sFile = vbNullString
If sFile <> "." Then ' relative path meaning this directory
If sFile <> ".." Then ' relative path meaning parent directory
extension = IO.Path.GetExtension(sFile)
If extension = ".xls" Or extension = ".xlsx" Then
newExtension = IO.Path.ChangeExtension(sFile, ".csv")
oXL = CreateObject("Excel.Application")
oXL.Visible = False
oXL.UserControl = False
oWB = oXL.Workbooks.Open("C:\Users\filePath\" & sFile)
oWB.SaveAs("C:\Users\filePath\" & newExtension)
oWB.Close()
oXL.Quit()
oWB = Nothing
oXL = Nothing
'file = IO.File.Create("C:\Users\filePath\" & newExtension)
'file.Close()
'IO.File.Delete("C:\Users\filePath\" & sFile)
'My.Computer.FileSystem.RenameFile("C:\Users\filePath\" & sFile, newExtension)
End If
End If
End If
sFile = Dir$()
Loop
sFile = Dir$("C:\Users\filePath" & "\*.*", vbDirectory)
Do Until sFile = vbNullString
If sFile <> "." Then ' relative path meaning this directory
If sFile <> ".." Then ' relative path meaning parent directory
extension = IO.Path.GetExtension(sFile)
If extension = ".csv" Then
importsFileList.Add(sFile)
End If
End If
End If
sFile = Dir$()
Loop
For Each importedFile In importsFileList
ImportFiles.Items.Add(importedFile)
Next
Does anyone have any other suggestions?