I need to replace commas in a large number of excel workbooks and then save them as csv, I have the following code but don't know why it isn't working:
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
These lines are where it seems to fail:
set oBookRange = oBook.ActiveWorkbook.Sheets(1)
oBookRange.Replace What:=",", Replacement:=" ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ReplaceFormat:=False
Replace:
Set oBookRange = oBook.ActiveWorkbook.Sheets(1)
with:
Set oBookRange = oBook.Sheets(1).Cells
There may be other problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.