简体   繁体   English

vbscript中CreateObject(“ Excel.Application”)上的“内存不足”

[英]“Out of Memory” on CreateObject(“Excel.Application”) in vbscript

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. 我正在尝试实现一个简单的vbscript,将一堆.xls文件转换为.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). 使用CreateObject时,即使我还没有做任何事情(例如,我还没有开始遍历文件),并且即使在启动计算机后立即尝试也遇到了“内存不足”错误(Windows 7 64位4GBram,闲置时使用约2.5GB)。 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. 我确实使用大约14Mb创建了一个EXCEL.EXE * 32进程,然后必须在任务管理器中手动将其杀死。

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. 编辑:修复了代码中的一些错误(有两个不同的名称用于文件对象,忘记了Dim oBook),该错误并没有引发错误,因为代码没有走那么远。

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). Edit2:所以我只是将其复制到Excel中的VBA Sub中,它按原样工作正常(好吧,发现了另一个愚蠢的错误,我不得不修改Wscript行)。 Any thoughts why I can´t create an excel object in cscript on my machine?? 有什么想法为什么不能在计算机上的cscript中创建excel对象?

Try using the right 32 or 64 bit cscript/wscript for excel which seems to be 32 bit. 尝试使用正确的32或64位cscript / wscript for excel(似乎是32位)。 c:\\windows\\syswow64 c:\\ windows \\ syswow64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CreateObject(“ Excel.Application”)不起作用 - CreateObject(“Excel.Application”) does not work WinWrap CreateObject(“ Excel.Application”)多个实例 - WinWrap CreateObject(“Excel.Application”) Multiple Instances CreateObject(“ Excel.Application”)并安装插件 - CreateObject(“Excel.Application”) and install Addins 使用 CreateObject("Excel.Application") 的 2 个 Excel 链接实例 - 2 linked instances of Excel using CreateObject("Excel.Application") CreateObject Excel.Application在循环期间在左键单击时引发错误 - CreateObject Excel.Application throws an error on left click during a loop 使用CreateObject(“ Excel.Application”)-未签名控件的问题 - Using CreateObject(“Excel.Application”) - issues with unsigned control CreateObject(“Excel.Application”).Workbooks.Open和Workbooks.Open之间的区别 - Difference between CreateObject(“Excel.Application”) .Workbooks.Open and just Workbooks.Open CreateObject(“ Excel.Application”)实例的行为与“ normal”(单击鼠标)实例不同 - CreateObject(“Excel.Application”) instance behaves differently than “normal” (point-click) instance Excel.Application异常 - Excel.Application Exception “新”Excel.Application与Excel.Application - “New” Excel.Application vs Excel.Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM