472,331 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

not quitting excel

Please help. I am using object.quit in an attempt to
quit an excel application that I started with createobject
("Excel.Application"). The code executes, but does not
stop the application. When I run the exact same code for
Access and Word, it works fine (app closes).

Any ideas? Any help would be appreciated.

Thanks,
Mike Sweet
Jul 21 '05 #1
7 2384
have you tried
System.Runtime.InteropServices.Marshal.ReleaseComO bject( excelObj );

after the quit method
This ought to do it

/morten

"Mike" <mi**********@fidelis-partners.com> wrote in message
news:01****************************@phx.gbl...
Please help. I am using object.quit in an attempt to
quit an excel application that I started with createobject
("Excel.Application"). The code executes, but does not
stop the application. When I run the exact same code for
Access and Word, it works fine (app closes).

Any ideas? Any help would be appreciated.

Thanks,
Mike Sweet

Jul 21 '05 #2
Morten,

Thank you for such a quick response. I tried your
suggestion and had no success. What's odd is that this
approach works if I replaced "excel.application"
with "word.application" or "access.application". I
wonder if this has something to do with my installation
of Excel. But what's also odd is that the quit method
works for Excel if I run it from an older version of vb.
It's just not working for vb .net 2003.

Below is the code. Would appreciate any insights.

Function validfile(ByVal in_file As String) As Boolean

Dim excel As Object

On Error Resume Next
validfile = True
excel = GetObject(, "excel.application")
If Err().Number <> 0 Then
excel = CreateObject("excel.application")
b_excelwasnotrunning = True
Err().Clear() ' Clear Err object in case
error occurred.
Else
b_excelwasnotrunning = False
End If
excel.Workbooks.Open(in_file)
If Err().Number <> 0 Then
validfile = False
Err().Clear()
End If
If b_excelwasnotrunning = True Then
excel.quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject
(excel)
excel = Nothing
End If
End Function

Thank you for any additional help.

Regards,
Mike Sweet
-----Original Message-----
have you tried
System.Runtime.InteropServices.Marshal.ReleaseCom Object( excelObj );
after the quit method
This ought to do it

/morten

"Mike" <mi**********@fidelis-partners.com> wrote in messagenews:01****************************@phx.gbl...
Please help. I am using object.quit in an attempt to
quit an excel application that I started with createobject ("Excel.Application"). The code executes, but does not
stop the application. When I run the exact same code for Access and Word, it works fine (app closes).

Any ideas? Any help would be appreciated.

Thanks,
Mike Sweet

.

Jul 21 '05 #3
On Tue, 16 Dec 2003 16:58:01 -0800, <an*******@discussions.microsoft.com> wrote:

¤ Morten,
¤
¤ Thank you for such a quick response. I tried your
¤ suggestion and had no success. What's odd is that this
¤ approach works if I replaced "excel.application"
¤ with "word.application" or "access.application". I
¤ wonder if this has something to do with my installation
¤ of Excel. But what's also odd is that the quit method
¤ works for Excel if I run it from an older version of vb.
¤ It's just not working for vb .net 2003.
¤
¤ Below is the code. Would appreciate any insights.
¤
¤ Function validfile(ByVal in_file As String) As Boolean
¤
¤ Dim excel As Object
¤
¤ On Error Resume Next
¤ validfile = True
¤ excel = GetObject(, "excel.application")
¤ If Err().Number <> 0 Then
¤ excel = CreateObject("excel.application")
¤ b_excelwasnotrunning = True
¤ Err().Clear() ' Clear Err object in case
¤ error occurred.
¤ Else
¤ b_excelwasnotrunning = False
¤ End If
¤ excel.Workbooks.Open(in_file)
¤ If Err().Number <> 0 Then
¤ validfile = False
¤ Err().Clear()
¤ End If
¤ If b_excelwasnotrunning = True Then
¤ excel.quit()
¤
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject
¤ (excel)
¤ excel = Nothing
¤ End If
¤
¤
¤ End Function
¤
¤ Thank you for any additional help.
¤
¤ Regards,
¤ Mike Sweet

Try not to create implicit objects. For example, if you create a Workbook object by opening a
Workbook, set the returned object to a variable:

ExcelWorkbook = excel.Workbooks.Open(in_file)

ExcelWorkbook.Close, False

ExcelWorkbook = Nothing
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Jul 21 '05 #4
On Tue, 16 Dec 2003 16:58:01 -0800, <an*******@discussions.microsoft.com> wrote:

¤ Morten,
¤
¤ Thank you for such a quick response. I tried your
¤ suggestion and had no success. What's odd is that this
¤ approach works if I replaced "excel.application"
¤ with "word.application" or "access.application". I
¤ wonder if this has something to do with my installation
¤ of Excel. But what's also odd is that the quit method
¤ works for Excel if I run it from an older version of vb.
¤ It's just not working for vb .net 2003.
¤
¤ Below is the code. Would appreciate any insights.
¤
¤ Function validfile(ByVal in_file As String) As Boolean
¤
¤ Dim excel As Object
¤
¤ On Error Resume Next
¤ validfile = True
¤ excel = GetObject(, "excel.application")
¤ If Err().Number <> 0 Then
¤ excel = CreateObject("excel.application")
¤ b_excelwasnotrunning = True
¤ Err().Clear() ' Clear Err object in case
¤ error occurred.
¤ Else
¤ b_excelwasnotrunning = False
¤ End If
¤ excel.Workbooks.Open(in_file)
¤ If Err().Number <> 0 Then
¤ validfile = False
¤ Err().Clear()
¤ End If
¤ If b_excelwasnotrunning = True Then
¤ excel.quit()
¤
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject
¤ (excel)
¤ excel = Nothing
¤ End If
¤
¤
¤ End Function
¤
¤ Thank you for any additional help.
¤
¤ Regards,
¤ Mike Sweet

Try not to create implicit objects. For example, if you create a Workbook object by opening a
Workbook, set the returned object to a variable:

ExcelWorkbook = excel.Workbooks.Open(in_file)

ExcelWorkbook.Close, False

ExcelWorkbook = Nothing
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Jul 21 '05 #5
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.ReleaseComO bject
(excel)
excel = Nothing
-----Original Message-----
On Tue, 16 Dec 2003 16:58:01 -0800, <an*******@discussions.microsoft.com> wrote:
¤ Morten,
¤
¤ Thank you for such a quick response. I tried your
¤ suggestion and had no success. What's odd is that this ¤ approach works if I replaced "excel.application"
¤ with "word.application" or "access.application". I
¤ wonder if this has something to do with my installation ¤ of Excel. But what's also odd is that the quit method
¤ works for Excel if I run it from an older version of vb. ¤ It's just not working for vb .net 2003.
¤
¤ Below is the code. Would appreciate any insights.
¤
¤ Function validfile(ByVal in_file As String) As Boolean
¤
¤ Dim excel As Object
¤
¤ On Error Resume Next
¤ validfile = True
¤ excel = GetObject(, "excel.application")
¤ If Err().Number <> 0 Then
¤ excel = CreateObject("excel.application")
¤ b_excelwasnotrunning = True
¤ Err().Clear() ' Clear Err object in case
¤ error occurred.
¤ Else
¤ b_excelwasnotrunning = False
¤ End If
¤ excel.Workbooks.Open(in_file)
¤ If Err().Number <> 0 Then
¤ validfile = False
¤ Err().Clear()
¤ End If
¤ If b_excelwasnotrunning = True Then
¤ excel.quit()
¤
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject
¤ (excel)
¤ excel = Nothing
¤ End If
¤
¤
¤ End Function
¤
¤ Thank you for any additional help.
¤
¤ Regards,
¤ Mike Sweet

Try not to create implicit objects. For example, if you create a Workbook object by opening aWorkbook, set the returned object to a variable:

ExcelWorkbook = excel.Workbooks.Open(in_file)

ExcelWorkbook.Close, False

ExcelWorkbook = Nothing
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
.

Jul 21 '05 #6
On Mon, 29 Dec 2003 08:00:21 -0800, "Mike" <an*******@discussions.microsoft.com> wrote:

¤ 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.ReleaseComO bject
¤ (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/de...assemblies.asp
http://msdn.microsoft.com/library/de...dc_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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Jul 21 '05 #7
Mike,
You need to ReleaseComObject on your excel workbook and any other excel
objects that you create before setting them to nothing.
Ron Allen
"Mike" <an*******@discussions.microsoft.com> wrote in message
news:1e****************************@phx.gbl...
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.ReleaseComO bject
(excel)
excel = Nothing
-----Original Message-----
On Tue, 16 Dec 2003 16:58:01 -0800, <an*******@discussions.microsoft.com> wrote:
¤ Morten,
¤
¤ Thank you for such a quick response. I tried your
¤ suggestion and had no success. What's odd is that this¤ approach works if I replaced "excel.application"
¤ with "word.application" or "access.application". I
¤ wonder if this has something to do with my installation¤ of Excel. But what's also odd is that the quit method
¤ works for Excel if I run it from an older version of vb.¤ It's just not working for vb .net 2003.
¤
¤ Below is the code. Would appreciate any insights.
¤
¤ Function validfile(ByVal in_file As String) As Boolean
¤
¤ Dim excel As Object
¤
¤ On Error Resume Next
¤ validfile = True
¤ excel = GetObject(, "excel.application")
¤ If Err().Number <> 0 Then
¤ excel = CreateObject("excel.application")
¤ b_excelwasnotrunning = True
¤ Err().Clear() ' Clear Err object in case
¤ error occurred.
¤ Else
¤ b_excelwasnotrunning = False
¤ End If
¤ excel.Workbooks.Open(in_file)
¤ If Err().Number <> 0 Then
¤ validfile = False
¤ Err().Clear()
¤ End If
¤ If b_excelwasnotrunning = True Then
¤ excel.quit()
¤
¤ System.Runtime.InteropServices.Marshal.ReleaseComO bject
¤ (excel)
¤ excel = Nothing
¤ End If
¤
¤
¤ End Function
¤
¤ Thank you for any additional help.
¤
¤ Regards,
¤ Mike Sweet

Try not to create implicit objects. For example, if you create a Workbook object by opening aWorkbook, set the returned object to a variable:

ExcelWorkbook = excel.Workbooks.Open(in_file)

ExcelWorkbook.Close, False

ExcelWorkbook = Nothing
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
.

Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Roys | last post by:
Hi Im doing something wrong in quitting the Word.Application in my VB program. I have General Declarations Dim AppWord As Word.Application ...
1
by: BadOmen | last post by:
I am using the GetActiveWindow() API but it returns 0 I have a remote that I activate this code with: Code: WinAmpHandler = GetActiveWindow...
0
by: Deaconess | last post by:
I am quitting this group - ever since I joined I have been at least 15 Microsoft viruses a day if not more. Good luck to you all. Back to Yahoo
8
by: bearophileHUGS | last post by:
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. ------------------- I am still ignorant about...
1
by: George | last post by:
I've seen questions of how to check if Excel is already running. If the user has already started Excel normally; call this Excel(User), then...
6
by: Mike | last post by:
Please help. I am using object.quit in an attempt to quit an excel application that I started with createobject ("Excel.Application"). The code...
1
by: Tony Hedge | last post by:
Hello, In my .NET code behind, I open up an excel file, and process all the rows in the worksheet that I'm interested in. Problem is when I'm...
4
by: Chris | last post by:
Hi, I'm puzzled by some strange behavior when my Python/Tkinter application quits (on linux): the terminal from which I started Python is messed...
1
by: subratamaji | last post by:
Hi, I am trying to open the form from the project explorer( Visual basic 6.0 ) by double clicking on a particular form ( frmDispatchEntry ) I...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.