Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process not quitting

Status
Not open for further replies.

PLV

Programmer
Apr 29, 2001
15
0
0
US
I'm using an excel application object in VB to create an excel document to show to the user.

The trouble is that when the user quits the excel application I have created, the excel process continues to run in the background. It seems to shut down only when my main VB application is closed.

I would like that when the user quits excel, the process stop immediately.

Maybe someone can help me...

Here's a part of my code showing the "closing procedure"
Code:
    Set objExcel = New Excel.Application
    Set objBook = objExcel.Workbooks.Add

'*****************
'some code to fill the excel document.....
'*******************

    'Restoring the normal display mode
    objExcel.DisplayAlerts = True
    objExcel.Interactive = True
    
    'Showing the book to the user
    objExcel.Visible = True
    
    
    'Quitting procedure
    Set objSheet = Nothing
    Set objBook = Nothing
    objExcel.UserControl = True
    Set objExcel = Nothing
    
    Unload Me
    Exit sub
 
You might try adding the following line before setting the objExcel to nothing

objExcel.UserControl = True
objExcel.Quit
Set objExcel = Nothing Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I've tried this but I cannot do it because I want the excel document to be visible to the user.

If I do the quit procedure, it quits immediately the excel process and the user cannot look at the document.




 
try defining the objExcel using the withevents keyword.

You can then capture the excel WorkbookBeforeClose event and close your program from there.

Matt
 
here's what i;ve found works for my users

declare xlActive as a module level boolean, then once excel has been opened do:

xlActive = True

xlApp.Visible = True
xlApp.EnableEvents = True

Do While xlActive
DoEvents
Loop
xlApp.EnableEvents = False

in the BeforeClose event set xlActive to false, this then allows the process to continue and you can put your quit where it belongs
 
Thx alot guys,

I've tried the Matt solution and Jonh24 too but none seems to kill the process completely.

When I do my application.quit (if I look in the taks manager) it changes the USER Object but doesn't kill the process.

The application.userName is blank at this stage.

I set my objet xlClass to nothing so my clss is terminated and I also set my application objetc to nothing to nothing so it is supposed to be destroyed too.

Is there something else reference on this excel thing?!?!?

No my code looks like this (with the last solution from Jonh and it's doing the same as the Matts's solution except The other one wasn't eating all my CPU!!! ;-) )
Code:
Private sub x
    Dim objBook As Excel.Workbook
    Dim objSheet As Excel.Worksheet
    Dim objSheetDACP As Excel.Worksheet
    Dim strTemp As String
    Dim xldoc As excelDoc
     
    On Error GoTo errsendtoexcel
    
    'Hide the form and display de hourglass cursor
    Me.Hide
    Me.Refresh

    Set xldoc = New excelDoc
    Set objBook = xldoc.objExcel.Workbooks.Add
    
    'Speeds up the data transfert to excel
    xldoc.objExcel.Interactive = False
    xldoc.objExcel.DisplayAlerts = False
'*********************************
'The code to fill the document
'*********************************

    'Restores the normal display
    xldoc.objExcel.Interactive = True
    xldoc.objExcel.DisplayAlerts = True
 
    
    xlActive = True
    xldoc.objExcel.Visible = True
 
    xldoc.objExcel.EnableEvents = True

    Do While xlActive
       DoEvents
    Loop
    
    xldoc.objExcel.EnableEvents = False
    

    'quitting procedure
    Set objSheet = Nothing
    Set objBook = Nothing
    xldoc.objExcel.Quit
    
    Set xldoc = Nothing
    
    Unload Me
    Exit Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top