How to close Excel for real 
Author Message
 How to close Excel for real

Hello, The following function, in a module class, will open an instance of
Excel but it will never unload it from the memory so that if I click again
on the button, a second instance of Excel will load and this is very
undesirable.  Even worst, if I click on another button that will open
another workbook, both workbooks will be active, depending on the sequence
of operation, there could be many instances of Excel.

    How could I unload Excel without closing the vb application?

Function OpenRead_File(ByVal sfile As String) As ADODB.Recordset
    Dim objExcel As Excel.Application

    If objExcel Is Nothing Then
        'Create new instance
        Set objExcel = CreateObject("Excel.Application")
        Else
        If objExcel.Visible = False Then
            'User closed Excel   'Destroy the hosed instance
            Set objExcel = Nothing
            'Create new instance
            Set objExcel = CreateObject("Excel.Application")
        End If
    End If

    objExcel.Workbooks.Open sFile, , , , , , , , , False
    objExcel.Visible = True

    Set objExcel = Nothing
    Application.Quit
End Function

thank you

Learner



Fri, 03 Sep 2004 07:22:05 GMT  
 How to close Excel for real
Hi,

Object model of Excel and Application particularly has
Quit method. You need to cal  it when you want to clse
Excel application

objExcel.Quit ...

Val

Quote:
>-----Original Message-----
>Hello, The following function, in a module class, will
open an instance of
>Excel but it will never unload it from the memory so that
if I click again
>on the button, a second instance of Excel will load and
this is very
>undesirable.  Even worst, if I click on another button
that will open
>another workbook, both workbooks will be active,

depending on the sequence
Quote:
>of operation, there could be many instances of Excel.

>    How could I unload Excel without closing the vb
application?

>Function OpenRead_File(ByVal sfile As String) As
ADODB.Recordset
>    Dim objExcel As Excel.Application

>    If objExcel Is Nothing Then
>        'Create new instance
>        Set objExcel = CreateObject("Excel.Application")
>        Else
>        If objExcel.Visible = False Then
>            'User closed Excel   'Destroy the hosed
instance
>            Set objExcel = Nothing
>            'Create new instance
>            Set objExcel = CreateObject

("Excel.Application")

- Show quoted text -

Quote:
>        End If
>    End If

>    objExcel.Workbooks.Open sFile, , , , , , , , , False
>    objExcel.Visible = True

>    Set objExcel = Nothing
>    Application.Quit
>End Function

>thank you

>Learner

>.



Fri, 03 Sep 2004 20:46:43 GMT  
 How to close Excel for real
Thank you Val,


Quote:
> Hi,

> Object model of Excel and Application particularly has
> Quit method. You need to cal  it when you want to clse
> Excel application

> objExcel.Quit ...

> Val

> >-----Original Message-----
> >Hello, The following function, in a module class, will
> open an instance of
> >Excel but it will never unload it from the memory so that
> if I click again
> >on the button, a second instance of Excel will load and
> this is very
> >undesirable.  Even worst, if I click on another button
> that will open
> >another workbook, both workbooks will be active,
> depending on the sequence
> >of operation, there could be many instances of Excel.

> >    How could I unload Excel without closing the vb
> application?

> >Function OpenRead_File(ByVal sfile As String) As
> ADODB.Recordset
> >    Dim objExcel As Excel.Application

> >    If objExcel Is Nothing Then
> >        'Create new instance
> >        Set objExcel = CreateObject("Excel.Application")
> >        Else
> >        If objExcel.Visible = False Then
> >            'User closed Excel   'Destroy the hosed
> instance
> >            Set objExcel = Nothing
> >            'Create new instance
> >            Set objExcel = CreateObject
> ("Excel.Application")
> >        End If
> >    End If

> >    objExcel.Workbooks.Open sFile, , , , , , , , , False
> >    objExcel.Visible = True

> >    Set objExcel = Nothing
> >    Application.Quit
> >End Function

> >thank you

> >Learner

> >.



Sat, 04 Sep 2004 06:24:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. real easy one, closing a connection

2. Outlook VBA - open Excel, read in two fields, send email with these, close excel

3. Accessing VBIDE.VBE.VBProjects via Excel in VB .NET Causes Excel To Crash When Closed

4. need help: Open Excel, run macro, save file, close Excel

5. Getting real-time data from Excel

6. Real time update between Access and Excel - how??

7. Real-Time DDE link with Excel or Word

8. graphs in real time under VBA in excel

9. Will EXCEL save as a REAL *.txt file ???

10. Retrieving real-time data from excel spreadsheet using VB5

11. Real easy one: Excel to text

12. Real Money, Real Fast!

 

 
Powered by phpBB® Forum Software