I have an export function on a form, which exports relevant data to an Excel file. Unfortunately, when I close down Excel, the excel.exe still stays running in the background. This means I can only use the sub/command button once.
I set all references to Nothing in the code but cannot work out what is causing this:
On Error GoTo Err_ModifyExportedExcelFileFormats
Application.SetOption "Show Status Bar", True
vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting export file... please wait.")
DoCmd.OutputTo acOutputForm, "A", acFormatXLS, "C:\A.xls", False
Dim xlApp As Object
Dim xlSheet As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Const cStartRow As Byte = 18
Const cStartColumn As Byte = 1
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open("C:\A.xls").Sheets(1)
With xlApp
[rest of code here] .....................
.............then at end
End With
Set xlApp = Nothing
Set xlSheet = Nothing
Set rst = Nothing
Set dbs = Nothing
vStatusBar = SysCmd(acSysCmdClearStatus)
Exit_ModifyExportedExcelFileFormats:
Set xlApp = Nothing
Set xlSheet = Nothing
Set rst = Nothing
Set dbs = Nothing
Exit Sub
Err_ModifyExportedExcelFileFormats:
vStatusBar = SysCmd(acSysCmdClearStatus)
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ModifyExportedExcelFileFormats
I set all references to Nothing in the code but cannot work out what is causing this:
On Error GoTo Err_ModifyExportedExcelFileFormats
Application.SetOption "Show Status Bar", True
vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting export file... please wait.")
DoCmd.OutputTo acOutputForm, "A", acFormatXLS, "C:\A.xls", False
Dim xlApp As Object
Dim xlSheet As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Const cStartRow As Byte = 18
Const cStartColumn As Byte = 1
Set xlApp = CreateObject("Excel.Application")
Set xlSheet = xlApp.Workbooks.Open("C:\A.xls").Sheets(1)
With xlApp
[rest of code here] .....................
.............then at end
End With
Set xlApp = Nothing
Set xlSheet = Nothing
Set rst = Nothing
Set dbs = Nothing
vStatusBar = SysCmd(acSysCmdClearStatus)
Exit_ModifyExportedExcelFileFormats:
Set xlApp = Nothing
Set xlSheet = Nothing
Set rst = Nothing
Set dbs = Nothing
Exit Sub
Err_ModifyExportedExcelFileFormats:
vStatusBar = SysCmd(acSysCmdClearStatus)
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ModifyExportedExcelFileFormats