Results 1 to 17 of 17

Thread: can't close excel --- excellent analysis provided !

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904

    can't close excel --- excellent analysis provided !

    discussed in great detail in the thread at:

    http://www.vbforums.com/showthread.p...hreadid=199211

    I have reduced the problem down to a minimal code set given below. This code is the entire app. Put this in the load event of a blank form & just run the app. Here's what happens:

    with task mgr, you'll see that there is no excel process prior to running the app, and when you run the app (which opens the form) task manager will show an excel process running. It SHOULDN'T be, since part of the code closes excel after having opened it. kill the app & excel closes, but it should have closed from the code at the end of the app.

    If you comment out the chart creation code, then run the app, task manager will show you as excel opens and closes, but when you put the chart creation code it, excel opens, but never closes.


    VB Code:
    1. Option Explicit
    2. '
    3. ' need to have, in the application path, an excel file called
    4. ' "book1.xls" and it has to have, in it's first worksheet
    5. ' (called "Sheet1") some numbers in the first 3 rows of the
    6. ' left-most column
    7. '
    8. Private Sub Form_Load()
    9.     Dim ch As ChartObject
    10.     Dim myObj1 As Object
    11.     Dim xlApp As Excel.Application
    12.     Dim xlsfilename As String
    13.    
    14.     xlsfilename = App.Path & "\book1.xls"
    15.     Set xlApp = New Excel.Application
    16.     xlApp.Workbooks.Open xlsfilename
    17.     xlApp.Worksheets("Sheet1").Activate
    18.     Set ch = xlApp.ActiveSheet.ChartObjects.Add(100, 20, 250, 170)
    19.     ch.Chart.ChartType = xlPie
    20.     Set myObj1 = xlApp.ActiveSheet.Range(cells(1, 1), cells(3, 1))
    21.     ch.Chart.SetSourceData Source:=myObj1, PlotBy:=xlColumns
    22.     If Err.Number <> 0 Then
    23.         MsgBox "error"
    24.     End If
    25.     Set ch = Nothing
    26.     Set myObj1 = Nothing
    27.     xlApp.DisplayAlerts = False
    28.     xlApp.ActiveWorkbook.Close SaveChanges:=True, FileName:=xlsfilename
    29.     xlApp.DisplayAlerts = True
    30.     xlApp.Quit
    31.     Set xlApp = Nothing
    32.     Exit Sub
    33. End Sub

    so, can anyone figure out how to get excel to close after creating the charts? all help greatly appreciated
    Last edited by phinds; Sep 25th, 2002 at 06:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width