我想循環訪問Excel中的工作表,並保持結束與excel的非限定參考。訪問VBA創建不合格的參考,而循環通過Excel表
Dim ExcelApp As Excel.Application
Dim ExcelWorkbook As Workbook
Dim ExcelWorkSheet As Worksheet
Dim i As Integer
Dim salesfile As String
Set ExcelApp = CreateObject("Excel.Application")
salesfile = "C:\filename"
Set ExcelWorkbook = ExcelApp.Workbooks.Open(salesfile)
With ExcelApp
With ExcelWorkbook
For Each ExcelWorkSheet In .Worksheets
i = i + 1
Next ExcelWorkSheet
End With
End With
ExcelWorkbook.Save
ExcelWorkbook.Close
Set ExcelWorkSheet = Nothing
Set ExcelWorkbook = Nothing
Set ExcelApp = Nothing
我已經試過移動的資格,採用.quit等,但仍最終在任務mananger一個EXCEL.EXE進程。這個問題在每個循環中都有定義。如果我在那之前關閉,那很好。
excel文件是否成功打開? ExcelWorkbook.worksheets.count的價值是什麼? – SeanC
您不需要使用ExcelApp循環。 –
是的,它打開。值爲8. – user3022724