to kill a excel process

  • Thread starter Thread starter han keat
  • Start date Start date
H

han keat

Hi all, I want to sent parse the email header and send the info to excel
worksheet. I do this by writing a macro in Outlook to create a excel
object. However, I have problem killing the excel process, everytime
after I run the macro I have to manually go to task manager to end the
process. Could anyone please help me?

Thank you!! =)

Function array_to_excel()

Dim objApp As Application
Dim objDL As Object
Dim objExcel As Excel.Application
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet
Dim objRange As Excel.Range
Dim file_name As String

file_name = "E:\excel\email.xls"

Set objExcel = new Excel.Application

objExcel.Visible = True

Set objWB = objExcel.Workbooks.Open(FileName:=file_name)
Set objWS= objWB.Worksheets(1)

'do something

objWB.Save
objExcel.DisplayAlerts = False
objWS.SaveAs FileName:=file_name, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
objWB.Close
objExcel.DisplayAlerts = True
objExcel.Quit

Set objWS = Nothing
Set objWB = Nothing
Set objExcel = Nothing

End Function
 
han,

While there may be something in your "do something" code that we are
missing, there is one gotcha in your SaveAs code. "xlNormal" belongs to
Excel and should be qualified with the application prefix...

objExcel.xlNormal

It is being left as an orphan still holding a reference to Excel.
Also, it might be better to set the worksheet and workbook to nothing before
quitting Excel.

Regards,
Jim Cone
San Francisco, CA
******************************************
 
Usually the instance of Excel only remains when there's a
connection of some kind still open.
I see you had a Range dim's, make sure that it's set to
nothing too.

Patrick Molloy
Microsoft Excel MVP
 
Back
Top