Close Excel With Access Automation (ever so popular problem) 
Author Message
 Close Excel With Access Automation (ever so popular problem)

Someone please help.

I can't get my Excel instance to close, here is my code:

Dim ExcelObj As Excel.Application
Dim TEM As Excel.Workbook
Dim TSH As Excel.Worksheet
Dim TEMPTH As String, SPATH As String
Set ExcelObj = New Excel.Application
Set TEM = ExcelObj.Workbooks.Add(TEMPTH)
Set TSH = ExcelObj.Workbooks(TEM.Name).Sheets(1)

ExcelObj.Application.Visible = False
ExcelObj.ActiveWorkbook.Close SAVECHANGES:=True, FileName:=SPATH &
"DIV" & DIVCURR & "_" & THEDIVDATE & ".XLS"

ExcelObj.Quit
Set ExcelObj = Nothing
Set TSH = Nothing
Set TEM = Nothing

I've tried swapping all the 'SET NOTHINGS' around, and still no
luck...
Can someone please please help.

Thanks mucho



Tue, 06 Apr 2004 16:02:39 GMT  
 Close Excel With Access Automation (ever so popular problem)
I had this problem and drove me nuts .... I don't know if it helps to
Set the objects to nothing  in order .. Range, worksheet, workbook,
Application - but that did stop one of my bugs.

Whatever changes you are making to the excel workbook/worksheet is the
problem. If you are using code that is selectin a range or cell
directly, it seems that excel wont close properly. Try similar to
this;

    Dim xlApp As New Excel.Application
    Dim wkb As Workbook
    Dim ws As Worksheet
    Dim myRange As Range
    Dim frmimport As String

    Set xlApp = New Excel.Application
    Set wkb = xlApp.Workbooks.Open ("c:\yourxcelbook.xls")
    Set ws = wkb.Worksheets(1)
    Set myRange = ws.Range("A1")
    frmimport = "Sample text or code or object whatever"

    With myRange
        .Value = frmimport
    End With

    xlApp.Run "ImportFile" <<<<<THIS IS RUNNING A MACRO IN EXCEL>>>>

    wkb.Close (False)
    xlApp.Quit

    Set myRange = Nothing
    Set ws = Nothing
    Set wkb = Nothing
    Set xlApp = Nothing

I hope this helps, it worked for me.

Grant

Quote:

> Someone please help.

> I can't get my Excel instance to close, here is my code:

> Dim ExcelObj As Excel.Application
> Dim TEM As Excel.Workbook
> Dim TSH As Excel.Worksheet
> Dim TEMPTH As String, SPATH As String
> Set ExcelObj = New Excel.Application
> Set TEM = ExcelObj.Workbooks.Add(TEMPTH)
> Set TSH = ExcelObj.Workbooks(TEM.Name).Sheets(1)

> ExcelObj.Application.Visible = False
> ExcelObj.ActiveWorkbook.Close SAVECHANGES:=True, FileName:=SPATH &
> "DIV" & DIVCURR & "_" & THEDIVDATE & ".XLS"

> ExcelObj.Quit
> Set ExcelObj = Nothing
> Set TSH = Nothing
> Set TEM = Nothing

> I've tried swapping all the 'SET NOTHINGS' around, and still no
> luck...
> Can someone please please help.

> Thanks mucho



Tue, 06 Apr 2004 23:56:31 GMT  
 Close Excel With Access Automation (ever so popular problem)
I experiment no problem with your code.

Maybe is it a service pack problem ?

Mathieu



Quote:
> Someone please help.

> I can't get my Excel instance to close, here is my code:

> Dim ExcelObj As Excel.Application
> Dim TEM As Excel.Workbook
> Dim TSH As Excel.Worksheet
> Dim TEMPTH As String, SPATH As String
> Set ExcelObj = New Excel.Application
> Set TEM = ExcelObj.Workbooks.Add(TEMPTH)
> Set TSH = ExcelObj.Workbooks(TEM.Name).Sheets(1)

> ExcelObj.Application.Visible = False
> ExcelObj.ActiveWorkbook.Close SAVECHANGES:=True, FileName:=SPATH &
> "DIV" & DIVCURR & "_" & THEDIVDATE & ".XLS"

> ExcelObj.Quit
> Set ExcelObj = Nothing
> Set TSH = Nothing
> Set TEM = Nothing

> I've tried swapping all the 'SET NOTHINGS' around, and still no
> luck...
> Can someone please please help.

> Thanks mucho



Tue, 06 Apr 2004 23:34:58 GMT  
 Close Excel With Access Automation (ever so popular problem)
Grant,

Thanks for the advice, I think you are indeed correct about the
range issue.  Before I inserted an Excel sort routine into
my code, the Excel session closed fine, but after putting in:

ExcelObj.Range("A" & ORIG & ":J" & SCOUNT + 1).Select
ExcelObj.Selection.Sort Key1:=Range("G" & ORIG), Order1:=xlAscending,
Key2:=Range("H" & ORIG), Order2:=xlAscending, Header:=xlGuess,
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
SortMethod:=xlPinYin

Things just don't seem to work.  Now I've tried just using TSH.RANGE
and
EXCELOBJ.SELECTION, I switched to EXCELOBJ.RANGE.  The program
closed out 50% of the time.  Sometimes it hung, sometimes it didn't.
I thought that was also odd.  I have another program that closes out
fine with this, but I can't seem to get this one to do the same....

If you got any other ideas, please let me know.

Thanks!



Fri, 09 Apr 2004 09:08:54 GMT  
 Close Excel With Access Automation (ever so popular problem)
I can't see any reason for this now that you have set the range, have
you tried closing down the workbook before you close the app. I
noticed in your code you close the app first???

Grant.

Quote:

> Grant,

> Thanks for the advice, I think you are indeed correct about the
> range issue.  Before I inserted an Excel sort routine into
> my code, the Excel session closed fine, but after putting in:

> ExcelObj.Range("A" & ORIG & ":J" & SCOUNT + 1).Select
> ExcelObj.Selection.Sort Key1:=Range("G" & ORIG), Order1:=xlAscending,
> Key2:=Range("H" & ORIG), Order2:=xlAscending, Header:=xlGuess,
> OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
> SortMethod:=xlPinYin

> Things just don't seem to work.  Now I've tried just using TSH.RANGE
> and
> EXCELOBJ.SELECTION, I switched to EXCELOBJ.RANGE.  The program
> closed out 50% of the time.  Sometimes it hung, sometimes it didn't.
> I thought that was also odd.  I have another program that closes out
> fine with this, but I can't seem to get this one to do the same....

> If you got any other ideas, please let me know.

> Thanks!



Fri, 09 Apr 2004 15:45:52 GMT  
 Close Excel With Access Automation (ever so popular problem)
'.selection' is the killer!
It always opens an extra session, which doesn't close itself.
The only way I have found round this is to use explicit addresses.

Regards

Peter Russell

Quote:

> Grant,

> Thanks for the advice, I think you are indeed correct about the
> range issue.  Before I inserted an Excel sort routine into
> my code, the Excel session closed fine, but after putting in:

> ExcelObj.Range("A" & ORIG & ":J" & SCOUNT + 1).Select
> ExcelObj.Selection.Sort Key1:=Range("G" & ORIG), Order1:=xlAscending,
> Key2:=Range("H" & ORIG), Order2:=xlAscending, Header:=xlGuess,
> OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
> SortMethod:=xlPinYin

> Things just don't seem to work.  Now I've tried just using TSH.RANGE
> and
> EXCELOBJ.SELECTION, I switched to EXCELOBJ.RANGE.  The program
> closed out 50% of the time.  Sometimes it hung, sometimes it didn't.
> I thought that was also odd.  I have another program that closes out
> fine with this, but I can't seem to get this one to do the same....

> If you got any other ideas, please let me know.

> Thanks!



Sat, 10 Apr 2004 14:31:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Excel Automation - Problem closing instance of Excel from with Access2000

2. Access/Excel Automation - Excel Not Closing

3. Access/Excel Automation - Excel Not Closing

4. Excel closing after closing workbook (OLE automation)

5. Excel won't close from Access Automation

6. Access Automation of Excel (closes at random)

7. VB Automation with Excel does not close Excel instance

8. Automation Problem Excel to Access

9. Automation Problem With Access 97/Excel 97

10. Access/Excel Automation Problem


 
Powered by phpBB® Forum Software © phpBB Group