Excel process still shows in TaskManager

N

noname

Hi,

I have an Excel MultiPage Form which loads on Workbook_Open event. It
has an Exit button which Unloads the Form & runs the following
Procedure to Close the Workbook and Quit Excel.

Private Sub cmd_Exit_Click()

Unload MainForm

Call QuitApplication

End Sub

Public Sub QuitApplication()

With ThisWorkbook
' Dim ans As Integer
' ans = MsgBox("Do you want to SAVE changes?", vbInformation +
vbYesNo, "Save Workbook")
' If ans = vbYes Then
.Close savechanges:=True
' Else
' .Close savechanges:=False
' End If
End With

Application.Visible = True
For Each obj In Excel.Application
Set obj = Nothing
Next obj

Application.Quit

End Sub


Why is Excel not quitting cleanly? I already checked if there are any
loaded Addins, which in my case there is only the default Funcres.xla
& ATPVBAEN.xla seen in VBE Editor.

I have tried to close all objects in code as well as in the form.



Anyone has any answers?
 
J

Jim Cone

Move the QuitApplication sub to a standard module and call it from the same sub that loaded the form....

MainForm.Show
Call QuitApplication
--
Jim Cone
Portland, Oregon USA

..
..

"noname" <[email protected]>
wrote in message
Hi,
I have an Excel MultiPage Form which loads on Workbook_Open event. It
has an Exit button which Unloads the Form & runs the following
Procedure to Close the Workbook and Quit Excel.

Private Sub cmd_Exit_Click()
Unload MainForm
Call QuitApplication
End Sub

Public Sub QuitApplication()
With ThisWorkbook
' Dim ans As Integer
' ans = MsgBox("Do you want to SAVE changes?", vbInformation +
vbYesNo, "Save Workbook")
' If ans = vbYes Then
.Close savechanges:=True
' Else
' .Close savechanges:=False
' End If
End With

Application.Visible = True
For Each obj In Excel.Application
Set obj = Nothing
Next obj
Application.Quit
End Sub


Why is Excel not quitting cleanly? I already checked if there are any
loaded Addins, which in my case there is only the default Funcres.xla
& ATPVBAEN.xla seen in VBE Editor.
I have tried to close all objects in code as well as in the form.
Anyone has any answers?
 
N

noname

Move the QuitApplication sub to a standard module and call it from the same sub that loaded the form....

MainForm.Show
Call QuitApplication
--
Jim Cone
Portland, Oregon  USA

.
.

"noname" <[email protected]>
wrote in messageHi,
I have an Excel MultiPage Form which loads on Workbook_Open event. It
has an Exit button which Unloads the Form & runs the following
Procedure to Close the Workbook and Quit Excel.

Private Sub cmd_Exit_Click()
    Unload MainForm
    Call QuitApplication
End Sub

Public Sub QuitApplication()
    With ThisWorkbook
'        Dim ans As Integer
'        ans = MsgBox("Do you want to SAVE changes?", vbInformation +
        vbYesNo, "Save Workbook")
'        If ans = vbYes Then
            .Close savechanges:=True
'        Else
'            .Close savechanges:=False
'        End If
    End With

    Application.Visible = True
    For Each obj In Excel.Application
        Set obj = Nothing
    Next obj
    Application.Quit
End Sub

Why is Excel not quitting cleanly? I already checked if there are any
loaded Addins, which in my case there is only the default Funcres.xla
& ATPVBAEN.xla seen in VBE Editor.
I have tried  to close all objects in code as well as in the form.
Anyone has any answers?

===========================
Hi Jim,

"and call it from the same sub that loaded the form...."

I did not understand this...

The QuitApplication() sub is located in a Standard Module. The Exit
Button is on the MainForm. There is no code in Workbook_Close(). The
Workbook_Open event shows as :

Private Sub Workbook_Open()

Application.Visible = False

Call DefineNames

Load MainForm

MainForm.Show

End Sub


Any ideas?
 
J

Jim Cone

Re: "and call it from the same sub that loaded the form"

Move the call to QuitApplication
From...
"Sub cmd_Exit_Click()"

To...
"Sub Workbook_Open".
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..

"noname" <[email protected]>
wrote in message

Move the QuitApplication sub to a standard module and call it from the same sub that loaded the form....

MainForm.Show
Call QuitApplication

===========================
Hi Jim,

"and call it from the same sub that loaded the form...."

I did not understand this...

The QuitApplication() sub is located in a Standard Module. The Exit
Button is on the MainForm. There is no code in Workbook_Close(). The
Workbook_Open event shows as :

Private Sub Workbook_Open()

Application.Visible = False

Call DefineNames

Load MainForm

MainForm.Show

End Sub

Any ideas?
 
N

noname

Re:  "and call it from the same sub that loaded the form"

Move the call to QuitApplication
From...
"Sub cmd_Exit_Click()"  

To...
"Sub Workbook_Open".
--
Jim Cone
Portland, Oregon  USAhttp://www.mediafire.com/PrimitiveSoftware

.
.

"noname" <[email protected]>
wrote in message



===========================
Hi Jim,

"and call it from the same sub that loaded the form...."

I did not understand this...

The QuitApplication()  sub is located in a Standard Module. The Exit
Button is on the MainForm. There is no code in Workbook_Close(). The
Workbook_Open event shows as :

Private Sub Workbook_Open()

    Application.Visible = False

    Call DefineNames

    Load MainForm

    MainForm.Show

End Sub

Any ideas?

====================

Hi Jim,

You mean like this:

Private Sub Workbook_Open()

Application.Visible = False

Call DefineNames

Load MainForm

MainForm.Show

Call QuitApplication

End Sub
 
N

noname

====================

Hi Jim,

You mean like this:

Private Sub Workbook_Open()

    Application.Visible = False

    Call DefineNames

    Load MainForm

    MainForm.Show

    Call QuitApplication

End Sub

==================

Well, i tried that, and its still the same....
 
J

Jim Cone

This part of your code doesn't work and generates an error. Get rid of it....
'---
For Each obj In Excel.Application
Set obj = Nothing
Next obj
'---
You don't say from where or how you are starting Excel.
I assume from a VB application. And you must have set a reference
to Excel in your project or are using CreateObject to return a reference.

So shown below is something I put together a few years back to provide
some general guidelines for automating Excel.
Note the last sentence...
'---
1. Set a reference to the primary Excel objects used in your program.
Dim xlApp As Excel.Application
Dim WB As Excel.Workbook
Dim WS As Excel.Worksheet

Set xlApp = New Excel.Application
Set WB = xlApp.Workbooks.Add
Set WS = WB.Sheets(1)

Use the appropriate reference Every Time you make reference to a spreadsheet.
Do not use Range(xx) - use WS.Range(xx)
Cells should be WS.Cells(10, 20) or _
WS.Range(WS.Cells(10, 20), WS.Cells(20, 40))

2. Avoid the use of ActiveSheet, ActiveWorkbook, Selection etc.
Use your object references.

3. Avoid the use of the "With" construct.

4. Set all objects to Nothing in the proper order - child then parent.
Set WS = Nothing
WB.Close SaveChanges:=True 'your choice
Set WB = Nothing
xlApp.Quit
Set xlApp = Nothing

Violating any of these guidelines can leave "orphans" that still refer
to Excel and prevent the application from closing.
--
Jim Cone
Portland, Oregon USA

..
..

"noname" <[email protected]>
wrote in message
On Sep 2, 6:02 pm, "Jim Cone" <[email protected]> wrote:

Well, i tried that, and its still the same....
 
N

noname

This part of your code doesn't work and generates an error.  Get rid ofit....
'---
    For Each obj In Excel.Application
        Set obj = Nothing
    Next obj
'---
You don't say from where or how you are starting Excel.
I assume from a VB application.  And you must have set a reference
to Excel in your project or are using CreateObject to return a reference.

So shown below is something I put together a few years back to provide
some general guidelines for automating Excel.
Note the last sentence...
'---
1. Set a reference to the primary Excel objects used in your program.
   Dim xlApp As Excel.Application
   Dim WB As Excel.Workbook
   Dim WS As Excel.Worksheet

   Set xlApp = New Excel.Application
   Set WB = xlApp.Workbooks.Add
   Set WS = WB.Sheets(1)

   Use the appropriate reference Every Time you make reference to a spreadsheet.
   Do not use Range(xx) - use WS.Range(xx)
   Cells should be WS.Cells(10, 20) or _
                   WS.Range(WS.Cells(10, 20), WS.Cells(20, 40))

2. Avoid the use of ActiveSheet, ActiveWorkbook, Selection etc.
   Use your object references.

3. Avoid the use of the "With" construct.

4. Set all objects to Nothing in the proper order - child then parent.
   Set WS = Nothing
   WB.Close SaveChanges:=True 'your choice
   Set WB = Nothing
   xlApp.Quit
   Set xlApp = Nothing

Violating any of these guidelines can leave "orphans" that still refer
to Excel and prevent the application from closing.
--
Jim Cone
Portland, Oregon  USA

.
.

"noname" <[email protected]>
wrote in message

Well, i tried that, and its still the same....

=================

Thanks Jim,

Though i was not Automating Excel application. Anyways, i found the
reason why it was happening. I was first closing the Workbook (where
the running code lay) and then trying to quit Excel Application. so
the code stops running once Workbook is closed & hence Excel
Application still stays in memory.

So solution:
----------------

Instead of closing Workbook, i just saved the workbook, using
Workbook.Save. Then ran the usual Application.Quit statement and that
did the work.

Thank n best regards. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top