ms access 2010 vba excel应用程序匹配不允许excel完全关闭

ms access 2010 vba excel应用程序匹配不允许excel完全关闭,vba,ms-access-2010,excel-2010,Vba,Ms Access 2010,Excel 2010,我正在使用excel通过access创建透视表,我遇到了一个问题,excel在代码末尾没有完全关闭(它仍然显示在Task Manager中)。为了解决这个问题,我注释掉了整个代码,并开始逐行取消设置,直到它复制了这个问题 我现在知道我的.Match语句是罪魁祸首,但我不知道如何纠正它。我尝试过使用Excel.Application.WorksheetFunction.Match和Excel.Application.Match,但仍然得到相同的结果。我知道第一个.Match语句位于If-IsErr

我正在使用excel通过access创建透视表,我遇到了一个问题,excel在代码末尾没有完全关闭(它仍然显示在Task Manager中)。为了解决这个问题,我注释掉了整个代码,并开始逐行取消设置,直到它复制了这个问题

我现在知道我的
.Match
语句是罪魁祸首,但我不知道如何纠正它。我尝试过使用
Excel.Application.WorksheetFunction.Match
Excel.Application.Match
,但仍然得到相同的结果。我知道第一个
.Match
语句位于
If-IsError
语句中,但我已经将
.Match
语句具体地分离出来

当我通过任务管理器结束进程并再次运行代码时,出现错误462“远程服务器计算机不存在或不可用”

这是我的代码,谢谢你的帮助

Sub exceltest()
'Reference to MS Excel Library and to DAO or ACEDAO
Dim oRS As DAO.Recordset
Dim i As Long
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Dim oWC As Excel.Worksheet
Dim oRange As Excel.Range
Dim oTable As Excel.PivotTable
Dim oField As Excel.PivotField
Dim z As Long
Dim y As Long
Dim pt As Excel.PivotTable
Dim pf As Excel.PivotField
Dim ctl As Control
Dim rpt As Report
Dim LAATotalRange As Excel.Range
Dim LAARange As Excel.Range
Dim LAANBRange As Excel.Range
Dim LAAWBRange As Excel.Range
Dim LUSTotalRange As Excel.Range
Dim LUSRange As Excel.Range
Dim LUSNBRange As Excel.Range
Dim LUSWBRange As Excel.Range
Dim GTotalRange As Excel.Range


Set oXL = New Excel.Application
oXL.Visible = False
Set oWB = oXL.Workbooks.Add
Set oWS = oWB.Sheets(1)
Set oRS = CurrentDb.OpenRecordset("tblRONData")

oWS.Cells(2, 1).CopyFromRecordset oRS

   For i = 0 To oRS.Fields.Count - 1
        oWS.Cells(1, i + 1) = oRS.Fields(i).Name
   Next i

'create pivot table

oWS.Cells.EntireColumn.AutoFit

Set oTable = oWS.PivotTableWizard

Set oField = oTable.PivotFields("Metal")
oField.Orientation = xlRowField

Set oField = oTable.PivotFields("Type")
oField.Orientation = xlRowField

Set oField = oTable.PivotFields("Sub Fleet")
oField.Orientation = xlRowField

Set oField = oTable.PivotFields("Day")
oField.Orientation = xlColumnField

Set oField = oTable.PivotFields("LAA NB")
oField.Orientation = xlDataField
oField.Function = xlCount

'format pivot table

Set oWC = oWB.Sheets("Sheet4")
Set oWS2 = oWB.Sheets("Sheet2")

oWS2.Cells(1, 1) = "TRUE"
oWS2.Cells(2, 1) = "LAA"
oWS2.Cells(3, 1) = "LUS"
oWS2.Cells(4, 1) = "LAA TOTAL"
oWS2.Cells(5, 1) = "LUS TOTAL"
oWS2.Cells(6, 1) = "NB TOTAL"
oWS2.Cells(7, 1) = "WB TOTAL"
oWS2.Cells(8, 1) = "GRAND TOTAL"


z = oWC.Cells(2, 4).End(xlToRight).Column
y = oWC.Cells(2, z).End(xlDown).Row
w = z - 1

sc1 = RGB(255, 197, 197) ' LUS NB
sc2 = RGB(255, 91, 91)   ' LUS WB
sc3 = RGB(209, 246, 255) ' LAA NB
sc4 = RGB(0, 173, 214)   ' LAA WB


If IsError(Excel.Application.WorksheetFunction.Match(oWS2.Cells(2, 1).Value, oWC.Columns(1), 0)) = False Then
'    LAARow = Excel.Application.Match(oWS2.Cells(2, 1).Value, oWC.Columns(1), 0)
'    LAATOTALRow = Excel.Application.Match(oWS2.Cells(4, 1).Value, oWC.Columns(1), 0)
'        Set LAATotalRange = oWC.Range(oWC.Cells(LAATOTALRow, 1), oWC.Cells(LAATOTALRow, z))
'            LAATotalRange.Font.Bold = True
'            LAATotalRange.Font.Size = 12
'        Set LAARange = oWC.Range(oWC.Cells(LAARow, 2), oWC.Cells(LAATOTALRow, 2))
'            If IsError(Excel.Application.Match(oWS2.Cells(6, 1).Value, LAARange, 0)) = False Then
'                LAANBRow = Excel.Application.Match(oWS2.Cells(6, 1).Value, LAARange, 0) + 2
'                Set LAANBRange = oWC.Range(oWC.Cells(LAANBRow, 2), oWC.Cells(LAANBRow, z))
'                LAANBRange.Interior.Color = sc3
 '               LAANBRange.Font.Bold = True
'                LAANBRange.Font.Size = 11
'            End If
'            If IsError(Excel.Application.Match(oWS2.Cells(7, 1).Value, LAARange, 0)) = False Then
'                LAAWBRow = Excel.Application.Match(oWS2.Cells(7, 1).Value, LAARange, 0) + 2
'                Set LAAWBRange = oWC.Range(oWC.Cells(LAAWBRow, 2), oWC.Cells(LAAWBRow, z))
'                LAAWBRange.Interior.Color = sc4
'                LAAWBRange.Font.Bold = True
'                LAAWBRange.Font.Size = 11
'            End If
End If

'If IsError(Excel.Application.Match(oWS2.Cells(3, 1).Value, oWC.Columns(1), 0)) = False Then
'    LUSRow = Excel.Application.Match(oWS2.Cells(3, 1).Value, oWC.Columns(1), 0)
'    LUSTOTALRow = Excel.Application.Match(oWS2.Cells(5, 1).Value, oWC.Columns(1), 0)
'        Set LUSTotalRange = oWC.Range(oWC.Cells(LUSTOTALRow, 1), oWC.Cells(LUSTOTALRow, z))
'            LUSTotalRange.Font.Bold = True
 '           LUSTotalRange.Font.Size = 12
 '       Set LUSRange = oWC.Range(oWC.Cells(LUSRow, 2), oWC.Cells(LUSTOTALRow, 2))
'            If IsError(Excel.Application.Match(oWS2.Cells(6, 1).Value, LUSRange, 0)) = False Then
 '               LUSNBRow = Excel.Application.Match(oWS2.Cells(6, 1).Value, LUSRange, 0) + LAATOTALRow
'                Set LUSNBRange = oWC.Range(oWC.Cells(LUSNBRow, 2), oWC.Cells(LUSNBRow, z))
'                LUSNBRange.Interior.Color = sc1
'                LUSNBRange.Font.Bold = True
'                LUSNBRange.Font.Size = 11
'            End If
'            If IsError(Excel.Application.Match(oWS2.Cells(7, 1).Value, LUSRange, 0)) = False Then
'                LUSWBRow = Excel.Application.Match(oWS2.Cells(7, 1).Value, LUSRange, 0) + LAATOTALRow
'                Set LUSWBRange = oWC.Range(oWC.Cells(LUSWBRow, 2), oWC.Cells(LUSWBRow, z))
'                LUSWBRange.Interior.Color = sc2
 '               LUSWBRangeFont.Bold = True
 '               LUSWBRange.Font.Size = 11
 '           End If
'End If

'Set GTotalRange = oWC.Range(oWC.Cells(y, 1), oWC.Cells(y, z))

'With GTotalRange
'     .Font.Bold = True
'     .Font.Size = 13
'     .Interior.Color = RGB(143, 202, 140)
'End With


 '   With oWC
 '       .Cells.Font.Name = "Arial monospaced for SAP"
 '       .Cells.Font.Size = 10
  '      .Range(.Columns(4), .Columns(z)).ColumnWidth = 6.3
  '      .Range(.Columns(4), .Columns(z)).WrapText = True
  '       Set oRange = .Range(.Cells(2, 1), .Cells(y, w))
  '      .PivotTables(1).ShowDrillIndicators = False
  '      .PivotTables(1).PivotCache.Refresh
   '     .PivotTables(1).MergeLabels = True
  '      .Range(.Columns(4), .Columns(z)).EntireColumn.AutoFit
  '      .Rows(1).EntireRow.Hidden = True
  '      .Columns(z).EntireColumn.Hidden = True

  '  End With




'Set pt = oWC.PivotTables(1)

'  For Each pf In pt.PivotFields
'      pf.EnableItemSelection = False
'  Next


'oRange.CurrentRegion.CopyPicture xlScreen, xlBitmap
'DoCmd.OpenReport ReportName:="rptRONData", View:=acViewDesign

'For Each ctl In Reports!rptRONData
'ctl.Name = "ctlDelPic"
'DeleteReportControl "rptRONData", "ctlDelPic"
'Next

'DoCmd.RunCommand acCmdPaste

'For Each ctl In Reports!rptRONData
'    ctl.Name = "ctlNewData"
'        With Reports!rptRONData.ctlNewData
'            .SizeMode = acOLESizeStretch
'            .Width = 23040
'        End With
'Next

'DoCmd.Close acReport, "rptRONData", acSaveYes


oWB.Close False
'oXL.Visible = True

Set oWB = Nothing
Set oWS = Nothing
Set oRS = Nothing
Set oTable = Nothing
Set oField = Nothing
Set oWC = Nothing
Set oWS2 = Nothing
Set LAATotalRange = Nothing
Set LAARange = Nothing
Set LAANBRange = Nothing
Set LAAWBRange = Nothing
Set LUSTotalRange = Nothing
Set LUSRange = Nothing
Set LUSNBRange = Nothing
Set LUSWBRange = Nothing
Set GTotalRange = Nothing
Set oRange = Nothing
Set pt = Nothing

oXL.Quit

Set oXL = Nothing


End Sub

oXL.WorksheetFunctionOMG,我不知道我昨天做了多长时间。我不敢相信事情竟那么简单。非常感谢。