我正在用excel编写VB脚本,将文件转换为CSV文件,并且收到无效的过程调用或参数错误。不知道如何解决此错误/
我尝试清理数据并以较小的片段运行脚本。无法解决错误/
Sub WRITE_BOM()
Set objworksheet = ThisWorkbook.Worksheets("BOM")
output_path = CreateObject("WScript.Shell").specialfolders("Desktop")
Set myfileFSO = CreateObject("Scripting.FileSystemObject")
output_file_name = "BOM" & ".txt"
Set myts = myfileFSO.CreateTextFile(output_path & "\" & output_file_name)
introw = 1
Count = 0
Do Until objworksheet.Cells(introw, 1).Value = ""
Count = Count + 1
introw = introw + 1
Loop
For i = 2 To Count
If i = 2 Then
myts.write "E;" & objworksheet.Cells(i, 1).Value & ";" &
objworksheet.Cells(i, 2).Value & ";" _
& objworksheet.Cells(i, 3) & ";" & objworksheet.Cells(i, 4).Value & ";" _
& objworksheet.Cells(i, 5).Value & ";" & objworksheet.Cells(i, 6).Value &
";" _
& objworksheet.Cells(i, 7).Value & ";" & objworksheet.Cells(i, 8).Value &
";" _
& objworksheet.Cells(i, 9).Value & ";" & objworksheet.Cells(i, 10).Value
& ";" _
& objworksheet.Cells(i, 11).Value & Chr(13) & Chr(10) _
& "L;" & objworksheet.Cells(i, 12).Value & ";" & objworksheet.Cells(i,
13).Value & ";" & objworksheet.Cells(i, 14).Value & ";" _
& objworksheet.Cells(i, 15).Value & ";" & objworksheet.Cells(i, 16).Value
& ";" & objworksheet.Cells(i, 17).Value & ";" _
& objworksheet.Cells(i, 18).Value & ";" & objworksheet.Cells(i, 19).Value
& ";" & objworksheet.Cells(i, 20).Value & ";" _
& objworksheet.Cells(i, 21).Value & ";" & objworksheet.Cells(i, 22).Value
& ";" & objworksheet.Cells(i, 23).Value & ";" _
& objworksheet.Cells(i, 24).Value & ";" & objworksheet.Cells(i, 25).Value
& ";" & objworksheet.Cells(i, 26).Value & ";" _
& objworksheet.Cells(i, 27).Value & ";" & objworksheet.Cells(i, 28).Value
& ";" & objworksheet.Cells(i, 29) & Chr(13) & Chr(10)
End If
If i > 2 Then
If objworksheet.Cells(i, 1).Value = objworksheet.Cells((i - 1), 1).Value
Then
myts.write "L;" & objworksheet.Cells(i, 12).Value & ";" &
objworksheet.Cells(i, 13).Value & ";" _
& objworksheet.Cells(i, 14).Value & ";" & objworksheet.Cells(i, 15).Value
& ";" _
& objworksheet.Cells(i, 16).Value & ";" & objworksheet.Cells(i, 17).Value
& ";" _
& objworksheet.Cells(i, 18).Value & ";" & objworksheet.Cells(i, 19).Value
& ";" _
& objworksheet.Cells(i, 20).Value & ";" & objworksheet.Cells(i, 21).Value
& ";" _
& objworksheet.Cells(i, 22).Value & ";" & objworksheet.Cells(i, 23).Value
& ";" _
& objworksheet.Cells(i, 24).Value & ";" & objworksheet.Cells(i, 25).Value
& ";" _
& objworksheet.Cells(i, 26).Value & ";" & objworksheet.Cells(i, 27).Value
& ";" _
& objworksheet.Cells(i, 28).Value & ";" & objworksheet.Cells(i, 29) &
Chr(13) & Chr(10)
Else
myts.write "E;" & objworksheet.Cells(i, 1).Value & ";" &
objworksheet.Cells(i, 2).Value & ";" _
& objworksheet.Cells(i, 3) & ";" & objworksheet.Cells(i, 4).Value & ";" _
& objworksheet.Cells(i, 5).Value & ";" & objworksheet.Cells(i, 6).Value &
";" _
& objworksheet.Cells(i, 7).Value & ";" & objworksheet.Cells(i, 8).Value &
";" _
& objworksheet.Cells(i, 9).Value & ";" & objworksheet.Cells(i, 10).Value
& ";" _
& objworksheet.Cells(i, 11).Value & Chr(13) & Chr(10) _
& "L;" & objworksheet.Cells(i, 12).Value & ";" & objworksheet.Cells(i,
13).Value & ";" _
& objworksheet.Cells(i, 14).Value & ";" & objworksheet.Cells(i, 15).Value
& ";" _
& objworksheet.Cells(i, 16).Value & ";" & objworksheet.Cells(i, 17).Value
& ";" _
& objworksheet.Cells(i, 18).Value & ";" & objworksheet.Cells(i, 19).Value
& ";" _
& objworksheet.Cells(i, 20).Value & ";" & objworksheet.Cells(i, 21).Value
& ";" _
& objworksheet.Cells(i, 22).Value & ";" & objworksheet.Cells(i, 23).Value
& ";" _
& objworksheet.Cells(i, 24).Value & ";" & objworksheet.Cells(i, 25).Value
& ";" _
& objworksheet.Cells(i, 26).Value & ";" & objworksheet.Cells(i, 27).Value
& ";" _
& objworksheet.Cells(i, 28).Value & ";" & objworksheet.Cells(i, 29) &
Chr(13) & Chr(10)
End If
End If
Next
' msgbox "Done."
End Sub
我可能会缺少什么?我正在Excel中本地运行此脚本。