Готово.
Берёт файл "D:\TMP\martensit\test.xls", пишет в "c:\testfile.csv".
Затем копируется в "c:\testfile2.csv".
Меняйте пути на свои.
Dim objExcel
Dim nEx
Dim wb
Dim excelSheet
Dim FSO
Dim MyFile
ActivateExcel
objExcel.screenupdating=false
On Error Resume Next
set wb = objExcel.Workbooks.open ("D:\TMP\martensit\test.xls")
if wb is nothing then
'msgbox "error, no file!"
objExcel.screenupdating=true
if nEx then objExcel.quit
end if
Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFile = FSO.CreateTextFile("c:\testfile.csv", True)
MyFile.WriteLine("название;цена1;цена2;цена3;артикул;вес;количество")
for sh = 1 to 3
Set excelSheet = GetSheet(wb, sh) ' ищем книгу с таким листом, если не найдёна - будет ошибка скрипта
LastCol = excelSheet.Cells(256).End(-4159).Column
for i=1 to LastCol
select case excelSheet.cells(i).value
case "название": nazv=i
case "цена1": c1=i
case "цена2": c2=i
case "цена3": c3=i
case "артикул": art=i
case "вес": ves=i
case "количество": kol=i
end select
next
LastRow = excelSheet.Cells(excelSheet.rows.count,nazv).End(-4162).row
'msgbox nazv & "-" & c1 & "-" & c2 & "-" & c3 & "-" & art & "-" & ves & "-" & kol
'название цена1 цена2 цена3 артикул вес количество
a=objExcel.range(excelSheet.Cells(1), excelSheet.Cells(LastRow,LastCol)).value
'msgbox "Последняя книга на листе " & sh & vblf & a(LastRow,nazv)
for x = 2 to LastRow
MyFile.WriteLine(a(x,nazv) & ";" & a(x,c1) & ";" & a(x,c2) & ";" & a(x,c3) & ";" & a(x,art) & ";" & a(x,ves) & ";" & a(x,kol))
'цена1;цена2;цена3;артикул;вес;количество")
next
next
wb.close 0
objExcel.screenupdating=true
if nEx then objExcel.quit
MyFile.Close
Set MyFile = fso.GetFile("c:\testfile.csv")
MyFile.Copy ("c:\testfile2.csv")
MyFile.Close
Private Function ActivateExcel()
On Error resume next
Set objExcel = GetObject(, "Excel.Application")
If objExcel Is Nothing Then
Set objExcel = CreateObject("Excel.Application")
'objExcel.Visible = True
nEx=true
End If
End Function
'The GetSheet method returns an Excel Sheet according to the sheetIdentifier
'ExcelApp - the Excel application which is the parent of the requested sheet
'sheetIdentifier - the name or the number of the requested Excel sheet
'return Nothing on failure
Function GetSheet(ExcelApp, sheetIdentifier) 'As Excel.worksheet
On Error Resume Next
Set GetSheet = ExcelApp.Worksheets.Item(sheetIdentifier)
On Error GoTo 0
End Function