VBScript使幻像进程运行;如何摆脱它们?

时间:2012-10-31 16:41:28

标签: excel vbscript

我正在使用vbscript进行一些自动化,每次运行脚本时,都会使进程“EXCEL.EXE”运行。我该如何预防?

代码:

Set oFs = CreateObject("Scripting.FileSystemObject")

set objExcel = createObject("Excel.Application")
set objWorkbook = objExcel.Workbooks.open("C:\test\test.xlsx")

for each sheet in objWorkbook.worksheets
wscript.echo(sheet.name)
set objSheet = sheet

next 

set objSheet = Nothing
set objworkbook = Nothing
set objExcel = Nothing
Set oFs = Nothing

如何在脚本退出后阻止EXCEL.exe继续运行?

1 个答案:

答案 0 :(得分:3)

使用它也可以关闭Excel。只需在下一步之后用以下代码替换您的代码。

set objSheet = Nothing
'Tells workbook to close without saving changes.
objWorkbook.Close false
set objworkbook = Nothing
'Tells Excel Application to quit.
objExcel.Quit
set objExcel = Nothing
Set oFs = Nothing