代码清理后,Excel进程卡在任务pipe理器中

Access有一个问题,打开一个Excel文件,从中读取并closures它

…但Excel进程不会从任务pipe理器中消失。

我已经find了完全相同的问题,但没有解决scheme,为我工作,所以我张贴我的情况在这里(见下文)。

如果我单击VB编辑器中的重置button,它会消失(或者如果我更改代码中的任何东西,这也会导致项目重置并摆脱不需要的Excel进程)。

任何想法(在Access中运行)的代码是什么?

我有以下类,称为clsTest

 Option Compare Database Option Explicit Private xlFolder As String Private xlFile As String Private xlSheet As String Private colShortURL As String Private oXL As Excel.Application Private oWB As Excel.Workbook Private oWS As Excel.Worksheet Private iLastRow As Long Private Sub Class_Initialize() Debug.Print "From class: Going through initialization inside class - constructor" xlFolder = "E:\COMH\Excel" xlFile = "Records v8z.xlsm" xlSheet = "comh" Set oXL = New Excel.Application Set oWB = oXL.Workbooks.Open(Filename:=(xlFolder & "\" & xlFile), ReadOnly:=True) Set oWS = oWB.Sheets(xlSheet) iLastRow = oWS.Range("A" & Rows.Count).End(xlUp).row End Sub Public Property Get ShortURL() As String ShortURL = "Hello World " & iLastRow End Property Private Sub Class_Terminate() Debug.Print "From class: Going through the clean-up inside class - destructor" oWB.Close SaveChanges:=False Set oWS = Nothing Set oWB = Nothing oXL.Quit Set oXL = Nothing End Sub 

我有以下模块使用上面的类:

 Option Compare Database Option Explicit Private Sub TestClass() Dim newExcel As clsTest Try: On Error GoTo Catch Set newExcel = New clsTest Debug.Print "Class instantiated, all good" Debug.Print "ShortURL=" & newExcel.ShortURL GoTo Finally Catch: Debug.Print "dealing with the error" Debug.Print Err.Description & " - " & Err.Number Finally: Debug.Print "doing the finally stuff" Set newExcel = Nothing End Sub 

当我运行上面的代码时,一切正常,我得到了我想要的结果:

 From class: Going through initialization inside class - constructor Class instantiated, all good ShortURL=Hello World 2603 doing the finally stuff From class: Going through the clean-up inside class - destructor 

没有错误,但Excel的过程仍然保留在“任务pipe理器进程”选项卡中。

很不错

尝试改变有问题的线路

  iLastRow = oWS.Range("A" & Rows.Count).End(xlUp).row 

对此( 您可能需要进一步参考应用级别的范围,我不记得这个,现在不能testing

 iLastRow = oWS.Range("A" & oWS.Rows.Count).End(xlUp).row 

可能的问题是,你没有一个完全合格的参考,请看这里