我正在尝试从 Outlook (Office 2010) 更新 Excel 文件。如何引用和访问 Excel?
作为一个简单的测试,我试图计算打开的工作簿的数量。当我运行它时,我得到 0,即使有 2 个打开。
Sub Test()
Dim xlApp As Excel.Application
Dim xlWBook As Excel.Workbook
Set xlApp = New Excel.Application
Debug.Print "xlApp.Workbooks.Count = " & xlApp.Workbooks.Count
On Error Resume Next
Set xlWBook = xlApp.Workbooks("Data.xlsx")
Err.Clear 'Clear error and open File Index
If xlWBook Is Nothing Then
Set xlWBook = xlApp.Workbooks.Open("C:\Users\Chris\Desktop\Data.xlsx")
End If
End Sub