Excel进程卡在任务管理器中 [英] Excel process stuck in Task Manager
问题描述
在Access中,我打开一个Excel文件,从中读取并关闭它.Excel进程不会脱离任务管理器.
In Access I open an Excel file, read from it and close it. The Excel process does not go away from Task Manager.
I found the same problem here but no solution that worked.
如果我单击VB编辑器中的重置"按钮,它就会消失(或者如果我更改代码中的任何内容,这也会导致项目重置并摆脱不需要的Excel进程).
If I click the Reset button in the VB Editor, it goes away (or if I change anything in the code, which also causes the project to reset and gets rid of the unwanted Excel process).
我有以下课程,称为 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
我有以下模块可用于以上课程:
I have the following Module to use above class:
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的过程仍保留在任务管理器的过程"选项卡中.
There are no errors but a process for Excel persists in Task Manager Processes tab.
推荐答案
很好的疑难解答!
尝试从以下位置更改有问题的行
try changing the problematic line from
iLastRow = oWS.Range("A" & Rows.Count).End(xlUp).row
对此(您可能需要走得更远,并在应用程序"级别参考该范围,我不记得了,现在无法测试)
iLastRow = oWS.Range("A" & oWS.Rows.Count).End(xlUp).row
可能的问题是您没有完全合格的参考,请参阅这里
The likely issue is that you do not have a fully qualified reference, see here
这篇关于Excel进程卡在任务管理器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!