我试图编写一个脚本来读取我的 excel 表并将日期与 Outlook 中的约会日期进行比较。
我不知道为什么我的代码没有找到任何 OLAppointment 项目来将他们的日期与我在工作表上的 dte 进行比较......
请参阅下面的代码
Public Function CheckAppointment(ByVal argCheckDate As Date) As Boolean
Dim oApp As Object
Dim oNameSpace As Object
Dim oApptItem As Object
Dim oFolder As Object
Dim oMeetingoApptItem As Object
Dim oObject As Object
On Error Resume Next
Set oApp = GetObject(, "Outlook.Application")
If oApp Is Nothing Then Set oApp = CreateObject("Outlook.Application")
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oFolder = oNameSpace.Session.GetDefaultFolder(9).Folders("aa")
CheckAppointment = False
For Each oObject In oFolder.Items
MsgBox oObject
If (oObject.Class = OLAppointment) Then
Set oApptItem = oObject
If oApptItem.Start = argCheckDate Then
CheckAppointment = True
End If
End If
Next oObject
Set oApp = Nothing
Set oNameSpace = Nothing
Set oApptItem = Nothing
Set oFolder = Nothing
Set oObject = Nothing
End Function
Public Sub Driver()
Dim dtCheck As Date
Dim sbCheck As String
dtCheck = DateValue("23/11/2013") + TimeValue("09:00:00")
If CheckAppointment(dtCheck) Then
MsgBox "Appointment found", vbOKOnly + vbInformation
Else
MsgBox "Appointment not found", vbOKOnly + vbExclamation
End If
End Sub
我在 2013 年 11 月 23 日的日历“aa”上创建了一个约会,但是当我尝试用我的宏搜索它时,总是给我“找不到约会”。我还尝试使用“Msgbox”显示通过以下方式找到的约会的属性:
Set oFolder = oNameSpace.Session.GetDefaultFolder(9).Folders("aa")
CheckAppointment = False
For Each oObject In oFolder.Items
MsgBox oObject.Subject
但无论如何不要去:\
对不起我糟糕的英语。