¤ Paul,
¤
¤ Thank you so much. The following code now does not work
¤ for me though - it does not close Excel. However, if I
¤ comment out the 3 excelworkbook lines, it does quit
¤ Excel. Any thoughts:
¤
¤ excel = CreateObject("excel.application")
¤ excelworkbook = excel.Workbooks.Open(in_file)
¤ excelworkbook.close()
¤ excelworkbook = Nothing
¤ excel.quit()
¤ System.Runtime.InteropServices.Marshal.ReleaseComObject
¤ (excel)
¤ excel = Nothing
¤
Which version of Excel are you using? If you are using XP or 2003 the primary interop assemblies
might be a better solution.
http://msdn.microsoft.com/library/d.../html/wrrefofficeprimaryinteropassemblies.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_oxppias.asp
As a last resort you can use the brute force method (API function calls) to terminate the Excel
process:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Int32
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Int32, ByVal wMsg
As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Public Function TerminateExcel()
Dim ClassName As String
Dim WindowHandle As Int32
Dim ReturnVal As Int32
Const WM_QUIT = &H12
Do
ClassName = "XLMain"
WindowHandle = FindWindow(ClassName, Nothing)
If WindowHandle Then
ReturnVal = PostMessage(WindowHandle, WM_QUIT, 0, 0)
End If
Loop Until WindowHandle = 0
End Function
Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)