Excel closing after closing workbook (OLE automation) 
Author Message
 Excel closing after closing workbook (OLE automation)

Using Excel 2002. When I start Excel from Word and open a workbook in vba,
Excel closes when I close this workbook.
This is the relevant code:

    Dim Ex As Excel.Application
    Dim ExBook As Workbook
    Dim ExSheet As Worksheet
    Const ERR_APP_NOTRUNNING As Long = 429

    On Error Resume Next

    Set Ex = GetObject(, "Excel.application")

    If Err = ERR_APP_NOTRUNNING Then
        'Excel not running so start it and open Test.xls
        Set Ex = New Excel.Application
        Set ExBook = Ex.Workbooks.Open("C:\Test.xls")
        Ex.Visible = True
    Else

Is this just normal behaviour or am I doing something wrong?
Thanks for any advice.

RBS



Mon, 22 Nov 2004 03:18:04 GMT  
 Excel closing after closing workbook (OLE automation)
Found the answer to this. I have to set UserControl to True:

        With Ex
            .Visible = True
            .UserControl = True
        End With

RBS


Quote:
> Using Excel 2002. When I start Excel from Word and open a workbook in vba,
> Excel closes when I close this workbook.
> This is the relevant code:

>     Dim Ex As Excel.Application
>     Dim ExBook As Workbook
>     Dim ExSheet As Worksheet
>     Const ERR_APP_NOTRUNNING As Long = 429

>     On Error Resume Next

>     Set Ex = GetObject(, "Excel.application")

>     If Err = ERR_APP_NOTRUNNING Then
>         'Excel not running so start it and open Test.xls
>         Set Ex = New Excel.Application
>         Set ExBook = Ex.Workbooks.Open("C:\Test.xls")
>         Ex.Visible = True
>     Else

> Is this just normal behaviour or am I doing something wrong?
> Thanks for any advice.

> RBS



Mon, 22 Nov 2004 03:45:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Missing OLE Automation and File Closing(Excel 97)

2. Excel 97 crash when opened with automation on workbook closing

3. Excel 97 crash when opened with automation on workbook closing

4. Closing a Workbook Closes Excel, Process Persists

5. Closing 1 workbook closes all workbooks

6. Closing Word Instance in OLE Automation

7. Close application when workbook is closed

8. Errors when closing a workbook using top right close (x) button

9. Help: Closing other .xls files automatically when workbook closed

10. Errors when closing a workbook using top right close (x) button


 
Powered by phpBB® Forum Software © phpBB Group