473,526 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2480
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
13552
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 Form_Load() Set AppWord = CreateObject("Word.Application")
1
7363
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 WinAMPhWnd = FindWindow("Winamp v1.x", vbNullString) I have the WinAmp window active but the GetActiveWindow returns a 0 instead of the window handler, way?
0
1142
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
2153
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 Tkinter. This little program, after pressing the "Go" eats more and more RAM, is it normal? Can it be avoided? (In normal programs this is isn't a real problem). ! import Tkinter
1
1596
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 vb.net code runs: myXL = CreateObject("Excel.application") Does this new instance of Excel(VB) work completely separate from the Excel(User)? If yes, why is there a need to check if Excel is running?...
6
678
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 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
1
1658
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 done and issue the quit method. The EXCEL process still exists in task manager (owner is ASPNET). Here is the code: Dim xcl As New Excel.Application Dim wbk As Excel.Workbook Dim xs As...
4
2093
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 up. If start up python, then import the code below, then start the program with Application(), then click the Quit button, my terminal never prints anything again (such as commands I type).
1
7916
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 am getting the :- RUN-TIME ERROR 50001 UNEXPECTED ERROR ; QUITTING.
0
7476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3314
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3317
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1702
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
549
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.