【问题标题】:After quit of excel in Access process stil shows in task manager until Quit access completely在Access进程中退出excel后仍然显示在任务管理器中,直到完全退出访问
【发布时间】:2016-11-11 03:52:13
【问题描述】:

我在退出后在任务管理器进程中显示 Excel 时遇到问题。我已经搜索了许多不同的答案,以便在任务管理器中仍然显示流程。我在其他函数中有其他 vba 代码可以很好地打开和关闭 excel 并从进程中删除,但是我在下面运行的当前事件只是将进程留在任务管理器中,直到我完全退出访问。请帮忙!!

 Private Sub status_ID_AfterUpdate()
 On Error GoTo Problems
 Dim filename As String
 Dim NewStatus As Long

 filename = "M:\Shared Documents\Job Cost Analysis\Hospital Active B2B Cases.xlsx" 

 Dim cell As Range
 Dim xlApp As Excel.Application
 Dim xlWB As Excel.Workbook
 Dim ws As Worksheet

 Set xlApp = New Excel.Application
 With xlApp
    .Visible = True
    Set xlWB = .Workbooks.Open(filename, , False)
    Set ws = .Worksheets("Active B2B cases")

ws.Columns("B:B").Select
Set cell = Selection.Find(What:=Me.client_ID.Value, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

If cell Is Nothing Then
'do nothing
Else
'Update active B2B sheet

If Me.status_ID.column(0) = "FINAL PROCESSING" Then
ws.Range("E" & (xlApp.cell.Row)).Value = "Final Processing"
MsgBox "The client's status has been updated on the Active B2B sheet"
ElseIf Me.status_ID.column(0) = "DATA ENTRY" Then
ws.Range("E" & (xlApp.cell.Row)).Value = "Data Entry"
MsgBox "The client's status has been updated on the Active B2B sheet"
ElseIf Me.status_ID.column(0) = "COMPLIANCE REVIEW" Then
ws.Range("E" & (xlApp.cell.Row)).Value = "Available To Audit"
MsgBox "The client's status has been updated on the Active B2B sheet"
ElseIf Me.status_ID.column(0) = "SENIOR COMPLIANCE REVIEW" Then
ws.Range("E" & (xlApp.cell.Row)).Value = "2nd Level Review"
MsgBox "The client's status has been updated on the Active B2B sheet"
ElseIf Me.status_ID.column(0) = "WAITING FOR DOCUMENTATION" Then
ws.Range("E" & (xlApp.cell.Row)).Value = "Pending - Doc"
MsgBox "The client's status has been updated on the Active B2B sheet"
ElseIf Me.status_ID.column(0) = "INVOICED" Then
xlApp.cell.EntireRow.Delete
MsgBox "The client has been removed from the Active B2B sheet"
End If

End If

End With
xlApp.DisplayAlerts = False
xlWB.SaveAs (filename)
xlWB.Close
xlApp.Quit

Set cell = Nothing
DoEvents
Set ws = Nothing
DoEvents
Set xlWB = Nothing
DoEvents
Set xlApp = Nothing
DoEvents
Exit Sub

Problems:
Err.Clear

Resume Next
End Sub

【问题讨论】:

  • 我依稀记得使用Selection会导致这种情况。试试Set cell = ws.Columns("B:B").Find(What:= ...(或使用额外的 Range 变量)。
  • 如果您xlWB.Close True 会发生什么?有时显式传递 SaveChanges 参数会有所帮助。
  • 如果注释掉错误处理程序会发生什么?
  • 我发现您对xlApp.cell 的使用令人困惑。 cell 是您子中的局部变量 - 您是否要引用它?
  • @Andre 通常我不会使用 xlApp,但在另一篇文章中看到要添加,它可以在有或没有 xlApp 的情况下工作,但仍然在流程中留下 excel

标签: excel vba ms-access taskmanager


【解决方案1】:

至少在出现更好的解决方案之前,您可以将其添加到代码的末尾(在将变量设置为 Nothing 之后)。注意:这将终止您机器上的所有 Excel 实例。

Call Shell("taskkill.exe /f /im excel.exe", vbNormalFocus)

【讨论】:

  • 我想到了这一点,但就像你提到的那样,它会杀死所有打开的 excel 工作簿,我不希望这样做,因为用户可能会打开他们正在处理的其他 excel 文件
猜你喜欢
  • 1970-01-01
  • 2012-02-24
  • 2015-03-12
  • 2016-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-26
  • 1970-01-01
相关资源
最近更新 更多