PDA

View Full Version : Sleeper: Can't shut down excel.exe process



JORDJB999
06-05-2008, 09:43 AM
Hi i have a problem, with this code. Its part of some code used in outlook to open an attachment in excel run a macro save and close. But it runs fine first time then wont work a second time untill i close outlook and ecxel down manually. Wen i watched the Task manager as it ran, the first instance of the excel.exe process doesnt disapear then i second excel.exe starts if it runs again. I think this maybe my problem, but im a total noooooob, so any help much apreciated. im using 2007.



Sub PrintAtt(file As String)
Dim xlApp As Object
Dim wb As Object
'in the background, create an instance of xl then open, print, quit
Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
xlApp.Workbooks.Open ("C:\Program Files\Microsoft Office\Office12\XLSTART\opips.XLSM")
On Error GoTo 0
xlApp.Workbooks.Open (file)
xlApp.Run ("opips.XLSM!stat2")
ActiveWorkbook.Save
ActiveWorkbook.Close savechanges:=False
xlApp.Quit
'tidy up
Set wb = Nothing
Set xlApp = Nothing
End Sub

Oorang
06-05-2008, 10:19 AM
Try setting a reference to Excel in your VB project then Dimming xlApp as Excel.Application and wb as Excel.Workbook. In the worst case the app should terminate when the call stack that called your sub terminates.

Ken Puls
06-05-2008, 10:06 PM
If Aaron's tip doesn't work, you could also hit it with the following sledgehammer:

Shell "taskkill /f /im Excel.exe", vbHide
Just an FYI, that I don't think this works on XP Home.

JORDJB999
06-06-2008, 01:55 AM
Thanks alot for your reply. I'll be honest i'm a total noob. Would you mind showing me in code wat u mean? If you need to, the whole of my code is in the outlook help forum. Cheers again.

JORDJB999
06-06-2008, 02:39 AM
Hi I used your "sledgehammer" and it did end the process but the second time i ran it i still got an error "Run time 462" "The remote server machine does not exist or is unavailable" When I do Debug The ActiveWorkbook save line is in yellow?
Any ideas much apreciated.