VB script excel.exe process termination

649 Views Asked by At

I have written a VB script wherein I am opening an excel file, running a macro, saving the file and then closing it.

There is a problem however, there are many "Excel.exe" getting clogged up in this process. Apparently, this is a common problem and saw the same post everywhere.

One person solved it using :

oWorkBook.Close SaveChanges:= False

But when I used this in my code it throws an error at this line. Maybe this is because I want to save and am saving it before the above line.

My code :

Option Explicit

Dim xlApp, xlBook, xlSheet

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Users\Pravin.Singh\Desktop\Marketing Vehicle Forecast_10302014_RB_fv.xlsm")

Set xlSheet = xlBook.worksheets.item(1)

xlApp.Run "Refresh_Report"
xlBook.Save
xlBook.Close 
xlApp.Quit

Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

Please let me know what I am doing wrong here. Set nothing is done here and closing all objects and excel is also done.

what else needs to be done here to prevent this "Excel.exe" clogging process?

0

There are 0 best solutions below