我想在Excel中使用VBA宏将共享Outlook日历中的约会从Excel中提取到Excel中。代码失败我是否尝试定义objOwner和olFolderCalendar如任一对象或Outlook.Recipient/Outlook.Folder在GetSharedDefaultFolder方法中。从共享Outlook日历中提取约会到Excel
我得到运行时错误“13”:在下面的行类型不匹配错误:
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("[email protected]")
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
非常好,谢谢瑞恩工作的一种享受! – Rixius