
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