Heenan, Lambert
Lambert.Heenan at AIG.com
Fri Jun 30 11:21:40 CDT 2006
Here's the routine I always use to close an Excel instance that I created with CreateObject Sub Excel_CloseWorkBook(xlApp As Excel.Application, Optional bSaveChanges As Boolean = False) Dim wb As Excel.Workbook On Error Resume Next If xlApp.Name > "" Then End If If Err.Number <> 0 Then Exit Sub On Error GoTo 0 For Each wb In xlApp.Workbooks 'Close all open workbooks wb.Close bSaveChanges Next wb xlApp.UserControl = False Set xlApp = Nothing End Sub I think the crucial line of code is " xlApp.UserControl = False". The on-line help has this to say about UserControl... True if the application is visible or if it was created or started by the user. False if you created or started the application programmatically by using the CreateObject or GetObject functions, and the application is hidden. Read/write Boolean. Remarks When the UserControl property is False for an object, that object is released when the last programmatic reference to the object is released. If this property is False, Microsoft Excel quits when the last object in the session is released. ... Of course that line of code may be entirely redundant, but it work for me! Lambert -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of ewaldt at gdls.com Sent: Friday, June 30, 2006 6:25 AM To: accessd at databaseadvisors.com Subject: [AccessD] Code not letting go of Excel I can't find anything wrong with this code, but Excel does not completely close down (i.e., it shows up in Task Manager). Could someone tell me what I'm missing, please? BTW, thanks to Duane Hookum for providing much of it; I'm sure the error is in my part, not his. TIA. Thomas F. Ewald FCS Database Manager General Dynamics Land Systems (586) 276-1256 ----------------------------------------------------------------------- Sub IPT_Export() Dim objXLApp As Object Dim objXLbook As Excel.Workbook Dim astrLinks As Variant Dim strFileName As String strFileName = InputBox("What should the new file be named? ", "Request for Information") & ".xls" Set objXLApp = CreateObject("Excel.Application") Set objXLApp = New Excel.Application Set objXLbook = objXLApp.Workbooks.Open("WRI_IPT.xlt", 0) DoCmd.SetWarnings False objXLbook.SaveAs (strFileName) astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks) ActiveWorkbook.BreakLink _ Name:=astrLinks(1), _ Type:=xlLinkTypeExcelLinks objXLbook.Save objXLbook.Close Set objXLbook = Nothing Set objXLApp = Nothing DoCmd.SetWarnings True End Sub This is an e-mail from General Dynamics Land Systems. It is for the intended recipient only and may contain confidential and privileged information. No one else may read, print, store, copy, forward or act in reliance on it or its attachments. If you are not the intended recipient, please return this message to the sender and delete the message and any attachments from your computer. Your cooperation is appreciated. -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com