View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default getting extra excel instance when controlling from access VBA

Duane,

Just looking at the first portion of your code...
I have made some changes that could help. (untested)
The workbook and worksheet objects are set to nothing
before quitting the application.
A separate object reference is used for the worksheet.
Use of the "With" construct was eliminated.
Eliminated references to anything "Active".

Regards,
Jim Cone
San Francisco, USA

'--------------------------
Private Sub Command11_Click()
Dim strWhat As String
Dim boolXL As Boolean
Dim objXL As Excel.Application
Dim objWorkSht As Excel.Worksheet
Dim objActiveWkb As Excel.Workbook

If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If

Set objActiveWkb = objXL.Workbooks.Add
Set objWorkSht = objActiveWkb.Worksheets(1)

objWorkSht.Cells(1, 1).Value = "Hello World"
strWhat = objWorkSht.Cells(1, 1).Value
objXL.Visible = True
Stop
FormatTest objXL
Reason_PSYS objXL
Set objWorkSht = Nothing
objActiveWkb.Close savechanges:=True, Filename:="test" & VBA.Str(10120602)
Set objActiveWkb = Nothing
If boolXL Then objXL.Application.Quit
Set objXL = Nothing
MsgBox strWhat
End Sub
'------------------------------------


"Duane Wilson" <Duane
wrote in message

I am writing a program in Access VBA to create an excel spreadsheet, import
data into it from Access queries, and format it. It works fine until I tried
putting a drop down list into it for data validation. Even that works, but I
am left with an instance of Excel in the task manager even though the
workbook has been closed and both the xlapp and xlworkbook has been set to
nothing. I can't even terminate the instance using a version of this code
that has only the get object parts and the close and set to nothing parts. It
recogizes that excel is open, grabs it; then when you do application.quit and
set to nothing, it just sits there in the task manager. Nothing seems to stop
it. Variations of this have been plaguing me for days. Please help.

'form module with 2 buttons, one which is not being used. Another form is in
db, but also not being used
Option Compare Database
Option Explicit
Dim xlsAppTest As Excel.Application
Dim xlsWorkbook As Excel.Workbook


Private Sub Command11_Click()
'************ Code Start **********

Dim objXL As Object
Dim strWhat As String, boolXL As Boolean
Dim objActiveWkb As Object

If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If

objXL.Application.Workbooks.Add
Set objActiveWkb = objXL.Application.ActiveWorkbook

With objActiveWkb
.Worksheets(1).Cells(1, 1) = "Hello World"
strWhat = .Worksheets(1).Cells(1, 1).Value
End With
objXL.Visible = True
Stop
FormatTest objXL
Reason_PSYS objXL
objActiveWkb.Close savechanges:=True, FileName:="test" & Str(10120602)

If boolXL Then objXL.Application.Quit
objXL.Application.Quit
Set objActiveWkb = Nothing: Set objXL = Nothing
MsgBox strWhat
End Sub
'************ Code End **********

- snip -