【发布时间】:2017-09-27 12:32:03
【问题描述】:
我正在尝试使用 Excel 中的 VBA 宏将约会从共享的 Outlook 日历提取到 Excel。无论我尝试将 objOwner 和 olFolderCalendar 定义为 Object 还是 Outlook.Recipient / ,代码都会失败Outlook.Folder 用于 GetSharedDefaultFolder 方法。
我在以下行收到 Run-time error '13': Type mismatch 错误:
Set olFolder = olNS.GetSharedDefaultFolder(objOwner, olFolderCalendar)
我做错了什么?
Sub ListAppointments()
Dim olApp As Object
Dim olNS As Object
Dim olFolder As Object
Dim olApt As Object
Dim objOwner As Object
Dim olFolderCalendar As Object
Dim NextRow As Long
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set objOwner = olNS.CreateRecipient("test@test.com")
objOwner.Resolve
If objOwner.Resolved Then
MsgBox objOwner.Name
Set olFolder = olNS.GetSharedDefaultFolder(objOwner, olFolderCalendar)
End If
Range("A1:D1").Value = Array("Subject", "Start", "End", "Location")
NextRow = 2
For Each olApt In olFolder.Items
Cells(NextRow, "A").Value = olApt.Subject
Cells(NextRow, "B").Value = olApt.Start
Cells(NextRow, "C").Value = olApt.End
Cells(NextRow, "D").Value = olApt.Location
NextRow = NextRow + 1
Next olApt
Set olApt = Nothing
Set olFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
Columns.AutoFit
End Sub
【问题讨论】: