More problems with Access/Excel interoperability 
Author Message
 More problems with Access/Excel interoperability

Hello!

I create an instance of Excel97 from Access97, run some Excel code and
attempt closing the automation object. Sometimes Excel will terminate
cleanly, on occasion Excel will keep{*filter*} around after a .Quit statement
and not return control to Access. To work around, I decided to harness some
API code from The Access Web and MSKB to terminate any lingering instances
of Excel.

Posted below is a code sample from the Main routine - where I observed the
problem. Also, I have posted a TestCloseApp routine which creates an Excel
instance, and calls fCloseApp (an API function from the Access Web) to
terminate the instance just created, and the result: Excel still hangs
around after fCloseApp.

So what am I missing?

I am reluctantly messing around with the TerminateProcess API function.

Thank you.

Note: I have left out the API declarations and procedures borrowed from
postings on the Access Web - API page.

Sub Main()
Dim oExcel as Object

'Use fIsAppRunning from The Access Web - Dev Ashish
If fIsAppRunning("excel") then
    Set oExcel=GetObject(,"excel.application")
Else
    Set oExcel=CreateObject("excel.application")
End If

With oExcel

    'Pass parameters

    'Execute Excel procedure

End With

oExcel.Application.Quit  'sometimes this does not close Excel

'Close Excel if an instance is{*filter*} around
If fIsAppRunning("excel") then
    'Use fCloseApp from The Access Web - Dev Ashish

    'This does not work! Why? See the simpler example below.
    Call fCloseApp("XLMain")
End If

If apiFindWindow("XLMAIN", vbNullString) <> 0 Then
  MsgBox "Excel instance still available."
End If

End Sub

'This simple example leaves an Excel instance{*filter*}. What am I missing?

Sub TestCloseApp()
Dim oApp as Object

Set oApp = CreateObject("Excel.application")

'Instead of using oApp.Application.Quit
Call fCloseApp("XLMAIN")

If apiFindWindow("XLMAIN", vbNullString) <> 0 Then
    MsgBox "Excel instance still available."
End If

End Sub



Mon, 22 Jan 2001 03:00:00 GMT  
 More problems with Access/Excel interoperability
HI S Mundkur,

I think because sometimes Excel might have a Dirty workbook open requiring
you to save it before proceeding.  Try using  ("Air Code")

Dim objWkb as object
    for each objWkb in oExcel.Workbooks
        objWkb.Close SaveChanges:=False    'To ignore changes
        'or
        'objWkb.Close SaveChanges:=True
        'to save changes
    next

    oExcel.Quit

It might be for the same reason that the fCloseApp routine doesn't close
since being a safe shutdown, it waiting for you to save changes.  To
_really_ force a shutdown, you have to terminate the process running inside
first, and SendMessge WM_CLOSE.  If the above doesn't work, please post
back.

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://www.*-*-*.com/ ~dashish )
---------------

:Hello!
:
:I create an instance of Excel97 from Access97, run some Excel code and
:attempt closing the automation object. Sometimes Excel will terminate
:cleanly, on occasion Excel will keep{*filter*} around after a .Quit statement
:and not return control to Access. To work around, I decided to harness some
:API code from The Access Web and MSKB to terminate any lingering instances
:of Excel.
:
:Posted below is a code sample from the Main routine - where I observed the
:problem. Also, I have posted a TestCloseApp routine which creates an Excel
:instance, and calls fCloseApp (an API function from the Access Web) to
:terminate the instance just created, and the result: Excel still hangs
:around after fCloseApp.
:
:So what am I missing?
:
:I am reluctantly messing around with the TerminateProcess API function.
:
:Thank you.
:
:
:
:Note: I have left out the API declarations and procedures borrowed from
:postings on the Access Web - API page.
:
:Sub Main()
:Dim oExcel as Object
:
:'Use fIsAppRunning from The Access Web - Dev Ashish
:If fIsAppRunning("excel") then
:    Set oExcel=GetObject(,"excel.application")
:Else
:    Set oExcel=CreateObject("excel.application")
:End If
:
:With oExcel
:
:    'Pass parameters
:
:    'Execute Excel procedure
:
:End With
:
:oExcel.Application.Quit  'sometimes this does not close Excel
:
:'Close Excel if an instance is{*filter*} around
:If fIsAppRunning("excel") then
:    'Use fCloseApp from The Access Web - Dev Ashish
:
:    'This does not work! Why? See the simpler example below.
:    Call fCloseApp("XLMain")
:End If
:
:If apiFindWindow("XLMAIN", vbNullString) <> 0 Then
:  MsgBox "Excel instance still available."
:End If
:
:End Sub
:
:
:'This simple example leaves an Excel instance{*filter*}. What am I missing?
:
:Sub TestCloseApp()
:Dim oApp as Object
:
:Set oApp = CreateObject("Excel.application")
:
:'Instead of using oApp.Application.Quit
:Call fCloseApp("XLMAIN")
:
:If apiFindWindow("XLMAIN", vbNullString) <> 0 Then
:    MsgBox "Excel instance still available."
:End If
:
:End Sub
:
:



Tue, 23 Jan 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problems with Access/Excel interoperability

2. Access-Excel Interoperability: Switching between two Application windows via automation (VBA)

3. Advice needed on Access-Excel interoperability

4. Excel & Word Interoperability

5. Excel & Word Interoperability

6. interoperability with outlook problems - URGENT

7. GC word-.net interoperability problem

8. .NET Language Interoperability Problem

9. problem with access coding accessing an excel spreadsheet

10. Running excel add-in (added into excel - not access) in Access VBA

11. read excel file in access 2000 lire fichier excel dans access 2000

12. OLE Access Excel (Datenimport von Excel in Access - muss nicht OLE sein)

 

 
Powered by phpBB® Forum Software