Excel应用程序将无法在Taskmanager中关闭

时间:2019-07-11 09:40:16

标签: access-vba

干杯, 我创建一个Excel.Application,保存工作簿(wb)后,我想使用quit和xl = none来确定Excel。但是用命令关闭它后,Taskmanager中有一个Excel应用程序。有什么主意我的错吗?

问候 蒂姆

Private Sub Befehl173_Click()
SQL = "SELECT Projekt FROM Projekt WHERE ID = " & projektNummer & ";"
Set result = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
tmp = result.Fields.Item(0).Value
DoCmd.OpenQuery _
"Abfrage4"
DoCmd.OutputTo acOutputQuery, "Abfrage4", acFormatXLSX, "P:\Datenbanken\Export\" & tmp & "_" & Date & ".xlsx"
DoCmd.Close acQuery, "Abfrage4"

Dim xl As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet



Dim myRange As Excel.Range
Set xl = New Excel.Application
strInputFile = "P:\Datenbanken\Export\" & tmp & "_" & Date & ".xlsx"
Set wb = xl.Workbooks.Open(strInputFile)
Set ws = wb.Sheets("Abfrage4")



lastrow = wb.Sheets("Abfrage4").Cells(Rows.Count, 6).End(xlUp).Row
wb.Sheets("Abfrage4").Range("b" & lastrow + 1) = "Gesamt"
wb.Sheets("Abfrage4").Range("c" & lastrow + 1) = xl.WorksheetFunction.Sum(wb.Sheets("Abfrage4").Range("c2:c" & lastrow))
wb.Sheets("Abfrage4").Range("d" & lastrow + 1) = xl.WorksheetFunction.Sum(wb.Sheets("Abfrage4").Range("d2:d" & lastrow))
wb.Sheets("Abfrage4").Range("e" & lastrow + 1) = xl.WorksheetFunction.Sum(wb.Sheets("Abfrage4").Range("e2:e" & lastrow))
wb.Sheets("Abfrage4").Range("f" & lastrow + 1) = xl.WorksheetFunction.Sum(wb.Sheets("Abfrage4").Range("f2:f" & lastrow))

wb.Sheets("Abfrage4").Range("c" & lastrow + 1).Font.Bold = True
wb.Sheets("Abfrage4").Range("d" & lastrow + 1).Font.Bold = True
wb.Sheets("Abfrage4").Range("e" & lastrow + 1).Font.Bold = True
wb.Sheets("Abfrage4").Range("f" & lastrow + 1).Font.Bold = True

wb.Sheets("Abfrage4").Range("C:F").NumberFormat = "#,##0.00 $"
wb.Sheets("Abfrage4").Range("A1").Interior.ColorIndex = 35
wb.Sheets("Abfrage4").Range("B1").Interior.ColorIndex = 35
wb.Sheets("Abfrage4").Range("C1").Interior.ColorIndex = 45
wb.Sheets("Abfrage4").Range("D1").Interior.ColorIndex = 35
wb.Sheets("Abfrage4").Range("E1").Interior.ColorIndex = 35
wb.Sheets("Abfrage4").Range("F1").Interior.ColorIndex = 35

wb.Sheets("Abfrage4").UsedRange.Borders.Weight = 2

wb.Save
wb.Close (True)


Set wb = Nothing
Set ws = Nothing
xl.Quit

Set xl = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

以相反的顺序关闭对象:

wb.Save
wb.Close (True)
Set ws = Nothing
Set wb = Nothing

为什么不使用您的ws工作表对象:

Set ws = wb.Worksheets("Abfrage4")

lastrow = ws.Cells(Rows.Count, 6).End(xlUp).Row
ws.Range("b" & lastrow + 1) = "Gesamt"