晚上,
尝试使用Outlook编写一些代码,这些代码将在Excel中生成类别和日期范围内所有会议的列表。
我能够很好地隔离会议,并且在循环浏览时,它会正确输出开始日期和时间,并且可以正确地安排主题,但是它会错误地与组织者和接收者有关(运行时错误287-应用程序已定义或对象定义的错误)
为澄清起见,这些行非常适用:
.Cells(i, 1).Value = oAppointmentItem.Start
.Cells(i, 2).Value = oAppointmentItem.Subject
此行失败(收件人也位于其下方):
.Cells(i, 3).Value = oAppointmentItem.Organizer
有什么想法吗?
已经尝试了围绕默认日历的各种选项以及处理约会项的各种方法,但无法使其正常工作。鉴于某些属性确实输出,发现它特别奇怪。
哦,如果我将约会放在监视窗口中,那么这些属性只会在value字段中显示一个“ <>”。
'Outlook variables
Dim oOl As Application
Dim oNS As NameSpace
Dim oCalendar As Object
Dim oItems
Dim oItemsFiltered
Dim MeetingRecipients As Recipients
Dim TempRecipient As Recipient
Dim oAppointmentItem As AppointmentItem
Dim DateStart As Date
Dim DateEnd As Date
Dim FilterCriteria As String
'Excel variables
Dim ExcelApp As Object 'Excel.Application
Dim ExcelWb As Excel.Workbook
Dim ExcelWs As Excel.Worksheet
Dim i As Integer
''Prepare Outlook
'Store references
Set oOl = New Outlook.Application
Set oNS = oOl.GetNamespace("MAPI")
Set oCalendar = oNS.GetDefaultFolder(olFolderCalendar)
Set oItems = oCalendar.Items
Debug.Print oItems.Count
'Set restrictions
DateStart = Date - 10
DateEnd = Date + 20
FilterCriteria = "[Start] >= '" & Format$(DateStart, "dd/mm/yyyy hh:mm AMPM") & "' AND [End] <= '" & Format$(DateEnd, "dd/mm/yyyy hh:mm AMPM") & "'"
'Debug.Print FilterCriteria
'Apply restrictions
Set oItemsFiltered = oItems.Restrict(FilterCriteria)
Debug.Print oItemsFiltered.Count
''Prepare Excel
Set ExcelApp = GetObject(, "Excel.Application")
ExcelApp.Visible = True
Set ExcelWb = ExcelApp.Workbooks.Add
Set ExcelWs = ExcelWb.Sheets(1)
i = 1
Dim ReqAtt() As String
''Export appointment data
'Loop appointments
For Each oAppointmentItem In oItemsFiltered
Debug.Print oAppointmentItem.Class
'Debug.Print oAppointmentItem.Subject & " - " & oAppointmentItem.Start
If InStr(oAppointmentItem.Categories, "Case") > 0 Then
With ExcelWs
.Cells(i, 1).Value = oAppointmentItem.Start
.Cells(i, 2).Value = oAppointmentItem.Subject
.Cells(i, 3).Value = oAppointmentItem.Organizer
Set MeetingRecipients = oAppointmentItem.Recipients
For Each TempRecipient In MeetingRecipients
.Cells(i, 4).Value = .Cells(i, 3).Value & "; " & TempRecipient
Next TempRecipient
End With
i = i + 1
End If
Next oAppointmentItem
Set oAppointmentItem = Nothing
Set oAppointments = Nothing
Set oNS = Nothing
Set oOl = Nothing
MsgBox "End"