excel vba访问不会closures此代码

您好我几分钟前张贴和somone asnwerd关于excel不closures的问题。 我正在使用访问来打开工作表并添加一个表。 Excel将不会closures导致问题的道路,因为当我在另一个函数中再次获得Excel对象时,我正在使用的工作表将不会打开,也不会格式化。 这是我的代码。 我以为我在这里是明确的,但也许我不是。 Excel只是不会closures。

Public Function BrooksFormatTableBrooks() Dim xlApp As Excel.Application Dim wb As Excel.Workbook Dim ws As Excel.Worksheet bfile = "S:\_Reports\Brooks\Tyco-Brooks Receiving Tracking MASTER - " MyFileName = bfile & Format(Date, "mm-dd-yyyy") & ".xls" On Error Resume Next Set xlApp = CreateObject("Excel.Application") On Error GoTo 0 Set wb = xlApp.Workbooks.Open(MyFileName) Set ws = wb.Sheets(1) ws.Activate wb.Sheets(1).Name = "RSSR_List" Set ws = wb.Sheets(1) ws.Activate xlApp.ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$F$312"), , xlYes).Name = _ "RSSR" ws.Range("A1:F312").Select DoEvents ws.Cells.Rows("2:2").Select xlApp.ActiveWindow.FreezePanes = False xlApp.ActiveWindow.FreezePanes = True ws.Columns("A:Z").HorizontalAlignment = xlCenter ws.Rows("1:1").Font.Bold = True ws.Rows("1:1").Font.ColorIndex = 1 ws.Rows("1:1").Interior.ColorIndex = 15 ws.Cells.Font.Name = "Calbri" ws.Cells.Font.Size = 8 ws.Cells.EntireColumn.AutoFit ws.Cells.EntireRow.AutoFit xlApp.Cells.Borders.LineStyle = xlContinuous xlApp.Cells.Borders.Weight = xlThin xlApp.Cells.Borders.ColorIndex = 0 ws.Cells.Rows("1:1").Select wb.CheckCompatibility = False wb.Save wb.CheckCompatibility = True wb.Close SaveChanges:=True xlApp.Quit Set xlApp = Nothing Set wb = Nothing Set ws = Nothing MsgBox "Table Add" End Function 

ws.Range("$A$1:$F$312")replaceRange("$A$1:$F$312") ,否则你将仍然有一个Excel应用程序对象的引用,直到你退出MSACCESS。