1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Option Explicit
Dim XL, WB, X, ColsCount, iRow, tmpText, Delim, RowsCount, CSV
WriteToCsvFile "C:\Temp\Test.xlsx", "C:\Temp\Result.csv"
'===========================
Sub WriteToCsvFile(xlsxFile, csvFile)
Delim = ";"
Set XL = CreateObject("Excel.Application")
XL.Visible = False
XL.DisplayAlerts = False
Set WB = XL.Workbooks.Open(xlsxFile)
RowsCount = WB.Activesheet.UsedRange.Rows.count
ColsCount = WB.Activesheet.UsedRange.Columns.count
iRow = 1
Set CSV = XL.Workbooks.Add()
Do Until iRow > RowsCount
tmpText = ""
For X = 1 To ColsCount - 1
tmpText = tmpText & WB.Sheets(1).Cells(iRow, X).Value & Delim
Next
tmpText = tmpText & WB.Sheets(1).Cells(iRow, ColsCount).Value
CSV.Sheets(1).Cells(iRow,1).Value = tmpText
iRow = iRow + 1
Loop
CSV.SaveAs csvFile
XL.Quit
Set XL = Nothing
End Sub |
Partager