我需要在大量excel工作簿中替换逗号,然后将它们保存为csv,我有以下代码,但不知道它为什么不工作:
csv_format = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)
Dim oBookRange
Set oBookRange = oBook.ActiveWorkbook.Sheets(1)
oBookRange.Replace What:=",", Replacement:=" ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ReplaceFormat:=False
oBook.SaveAs dest_file, csv_format
oBook.Close False
oExcel.Quit
这些行似乎失败了:
set oBookRange = oBook.ActiveWorkbook.Sheets(1)
oBookRange.Replace What:=",", Replacement:=" ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ReplaceFormat:=False
答案 0 :(得分:1)
替换:
Set oBookRange = oBook.ActiveWorkbook.Sheets(1)
使用:
Set oBookRange = oBook.Sheets(1).Cells
可能还有其他问题。