|
-
Sep 24th, 2002, 09:11 AM
#1
Thread Starter
PowerPoster
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:
Option Explicit
'
' need to have, in the application path, an excel file called
' "book1.xls" and it has to have, in it's first worksheet
' (called "Sheet1") some numbers in the first 3 rows of the
' left-most column
'
Private Sub Form_Load()
Dim ch As ChartObject
Dim myObj1 As Object
Dim xlApp As Excel.Application
Dim xlsfilename As String
xlsfilename = App.Path & "\book1.xls"
Set xlApp = New Excel.Application
xlApp.Workbooks.Open xlsfilename
xlApp.Worksheets("Sheet1").Activate
Set ch = xlApp.ActiveSheet.ChartObjects.Add(100, 20, 250, 170)
ch.Chart.ChartType = xlPie
Set myObj1 = xlApp.ActiveSheet.Range(cells(1, 1), cells(3, 1))
ch.Chart.SetSourceData Source:=myObj1, PlotBy:=xlColumns
If Err.Number <> 0 Then
MsgBox "error"
End If
Set ch = Nothing
Set myObj1 = Nothing
xlApp.DisplayAlerts = False
xlApp.ActiveWorkbook.Close SaveChanges:=True, FileName:=xlsfilename
xlApp.DisplayAlerts = True
xlApp.Quit
Set xlApp = Nothing
Exit Sub
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|