MSAccess 2010 VBA Excel进程不终止

我正在使用Window 7 SP1和MS Office 2010.我正在Access 2010中运行查询,并将结果写入到Excel 2010的报表中,并注意到Excel的实例没有从进程列表中终止。 为了确保它不是我的代码,我已经把它简化了。

  1. 以下代码按预期方式打开并终止Excel:

    Public Sub Test() Dim strRptDirPath As String: strRptDirPath = "C:\Projects\WeeklyAlarms\Report\" Dim xlApp As Object ' Dim xlWkBk As Object ' Dim xlWkSht As Object Dim strRptTl As String: strRptTl = "Report Template.xls" Dim strRptSht As String: strRptSht = "Rpt" Set xlApp = CreateObject("Excel.Application") xlApp.Visible = False ' Set xlWkBk = xlApp.Workbooks.Open(strRptDir & strRptTl) ' Set xlWkSht = xlWkBk.Worksheets(strRptSht) ' ' xlWkSht.Cells(1, 1).Value = "TEST 1" ' xlWkSht.Cells(2, 2).Value = "TEST 2" ' xlWkSht.Cells(3, 3).Value = "TEST 3" ' ' xlWkBk.SaveAs (strRptDirPath & "TESTING.xls") ' xlWkBk.Close xlApp.Quit ' Set xlWkSht = Nothing ' Set xlWkBk = Nothing Set xlApp = Nothing End Sub 
  2. 但是,如果我参考工作簿,Excel进程实例不会终止。 在closures访问后的一段时间内,通过通话主题进行search引起进程终止,在ping之后超时“ping” – 在这里不是这种情况。

     Public Sub Test() Dim strRptDirPath As String: strRptDirPath = "C:\Projects\WeeklyAlarms\Report\" Dim xlApp As Object Dim xlWkBk As Object ' Dim xlWkSht As Object Dim strRptTl As String: strRptTl = "Report Template.xls" Dim strRptSht As String: strRptSht = "Rpt" Set xlApp = CreateObject("Excel.Application") xlApp.Visible = False Set xlWkBk = xlApp.Workbooks.Open(strRptDir & strRptTl) ' Set xlWkSht = xlWkBk.Worksheets(strRptSht) ' ' xlWkSht.Cells(1, 1).Value = "TEST 1" ' xlWkSht.Cells(2, 2).Value = "TEST 2" ' xlWkSht.Cells(3, 3).Value = "TEST 3" xlWkBk.SaveAs (strRptDirPath & "TESTING.xls") xlWkBk.Close xlApp.Quit ' Set xlWkSht = Nothing Set xlWkBk = Nothing Set xlApp = Nothing End Sub 

我已经取消选中Microsoft Excel 14.0对象库引用。 我不认为我有任何全球性的参考电话。 我不能看到我做错了什么。

尝试使用以下命令replacexlWkBk.SaveAs (strRptDirPath & "TESTING.xls")行后面的所有内容:

 If Not xlWkBk Is Nothing Then xlWkBk.Save xlWkBk.Close Set xlWkBk = Nothing End If If Not xlApp Is Nothing Then xlApp.Quit Set xlApp = Nothing End If 

像这样设置,确保了一切都如预期的那样结束