Private Sub SaveExcelFileAsCVSFile()
Dim excelfile As Microsoft.Office.Interop.Excel.Application =
New Microsoft.Office.Interop.Excel.Application
Dim sFileName As String
Dim wb As Workbook = excelfile.Workbooks.Open( _
"FILE.xls", CorruptLoad:=XlCorruptLoad.xlRepairFile)
sFileName = wb.Path & "\FILE.csv"
wb.SaveAs(sFileName, XlFileFormat.xlCSV, XlSaveAsAccessMode.xlNoChange)
wb.Close()
excelfile.Quit()
End Sub
Posts tonen met het label Excel. Alle posts tonen
Posts tonen met het label Excel. Alle posts tonen
maandag 14 december 2009
Export excel file to csv (VBA Macro)
Set Separator (;)
Sub SaveToCSVFile()
Dim fs As Object, a As Object, i As Integer, j As Integer, s As String, t As String, l As String, mn As String
Set fs = CreateObject("Scripting.FileSystemObject")
Dim newFileName As String
newFileName = ThisWorkbook.FullName
newFileName = Replace(newFileName, ".xls", ".csv")
Set a = fs.CreateTextFile(newFileName, True)
Range("A1").Select
i = ActiveCell.CurrentRegion.Columns.Count
ActiveCell.CurrentRegion.EntireRow.Delete
For rowNumber = 1 To Range("A65536").End(xlUp).Row
s = ""
Col = 1
For j = 0 To i
s = s & Cells(rowNumber, Col) & ";" 'Separator
Col = Col + 1
Next j
a.writeline s 'write line
Next rowNumber
End Sub
Sub SaveToCSVFile()
Dim fs As Object, a As Object, i As Integer, j As Integer, s As String, t As String, l As String, mn As String
Set fs = CreateObject("Scripting.FileSystemObject")
Dim newFileName As String
newFileName = ThisWorkbook.FullName
newFileName = Replace(newFileName, ".xls", ".csv")
Set a = fs.CreateTextFile(newFileName, True)
Range("A1").Select
i = ActiveCell.CurrentRegion.Columns.Count
ActiveCell.CurrentRegion.EntireRow.Delete
For rowNumber = 1 To Range("A65536").End(xlUp).Row
s = ""
Col = 1
For j = 0 To i
s = s & Cells(rowNumber, Col) & ";" 'Separator
Col = Col + 1
Next j
a.writeline s 'write line
Next rowNumber
End Sub
Abonneren op:
Posts (Atom)