Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instance of Excel running

Status
Not open for further replies.

cmz21

Programmer
May 5, 2005
110
US
Hello,
I am using the following code to transfer data from an excel sheet into access. The code works fine except that it leaves an instance of excel running in the background. I thought that I have killed all objects running, but I can't get rid of the excel. Is there something I am missing.

Any thoughts would be a great help.

Thanks


Function fnLoadTable()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook

'Delete old data from tables
CurrentDb.Execute ("DELETE tblTable.* FROM tblTable")

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(FileName:="C:\File Path\filename.xls")

'Load data from spreadsheet to table
DoCmd.TransferSpreadsheet transfertype:=acImport, TableName:="Table", FileName:= C:\File Path\filename.xls ", Hasfieldnames:=True, Range:="SheetName!", SpreadsheetType:=5

xlBook.Close
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
End Function
 
You don't need any OLE Automation for the TransferSpreadsheet method ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
TransferSpreadsheet does not require to have an excel instance created, so you can have only one line with DoCmd in the above code. If you post full code, fnLoadTable should be rather Sub than Function. If you still need an excel instance, add xlApp.Visible=True to see what happens with it.

combo
 
Thank You both for your help. I do not need to open Excel, so I won't. I will also change this to a sub.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top