0
votes

OK, I´ve looked around quite a bit and I haven´t seem to find anyone thats even had the same problem. I´m trying to implement a simple vbscript to convert a bunch of .xls files to .csv. As soon as I use CreateObject I get an "Out of Memory" error, even though I havn´t done anything yet (ie I havn´t started iterating through the files) and even if I try right after starting up my machine (Windows 7 64 bit 4GBram, about 2.5GB used at idle). The code is the following

Dim path1, path2, csvname

path1 = "path1"
path2 = "path2"

Dim fso, folder, files
Set fso = CreateObject("Scripting.FileSystemObject" )
Set folder = fso.GetFolder(path1)
Set files = folder.Files

Dim oExcel, oBook
Set oExcel = CreateObject("Excel.Application")

for each f in files
    Set oBook = oExcel.Workbooks.Open(path1 & "\" f.name)
    csvname = path2 & Left(f.name,len(f.name)-4) & ".csv"
    WScript.Echo csvname
    oBook.SaveAs csvname, 6
    oBook.Close False
next

oExcel.Quit
WScript.Echo "Done"

I do get an EXCEL.EXE*32 process created, using about 14Mb, that I then have to kill manually in the task manager.

Thanks!

Edit: fixed a few bugs in the code (had two different names used for file object, forgot to Dim oBook) which hadn´t thrown an error because the code wasn´t getting that far.

Edit2: So I just copied this into a VBA Sub in Excel and it worked fine as is (well, found another stupid bug, and I had to nix the Wscript lines). Any thoughts why I can´t create an excel object in cscript on my machine??

1
VBS looks fine to me except assuming the file extension is 4 characters. You may want to make the excel object visible to troubleshoot visually by oExcel.Visible = True just after creating it. - PatricK

1 Answers

0
votes

Try using the right 32 or 64 bit cscript/wscript for excel which seems to be 32 bit. c:\windows\syswow64