我想向associateEmail和branchManagerEmail发送会议邀请,其中会员的会议显示为“olOutOfOffice”,但分行经理显示为“olFree”。
当我想要收件人时,看起来Busny Status属性在Appointment上。
我知道Outlook会单独保存这两个值,因为一个人可以进入并在接受后更改该值。
这是我到目前为止所拥有的。
Function SendMeetingRequest(subject As String, location As String, startDateTime As Date, durationMinutes As Integer, associateEmail As String, branchManagerEmail As String, allDayEvent As Boolean) As Boolean
On Error GoTo ErrorHandler
SendMeetingRequest = True
Dim myOutlook As Object
Dim myApt As AppointmentItem
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")
' Create the AppointmentItem
Set myApt = myOutlook.CreateItem(olAppointmentItem) ' Set the appointment properties
Dim r As recipient
Set r = myApt.recipients.Add(associateEmail)
r.Type = OlMeetingRecipientType.olRequired
Set r = myApt.recipients.Add(branchManagerEmail)
r.Type = OlMeetingRecipientType.olOptional
With myApt
.subject = subject
.location = location
.Start = startDateTime
.duration = durationMinutes
.MeetingStatus = olMeeting
.allDayEvent = allDayEvent
.BusyStatus = olFree
.ReminderSet = False
.Save
.send
End With
Exit Function
ErrorHandler:
MsgBox Err & ": " & Error(Err)
SendMeetingRequest = False
End Function
答案 0 :(得分:1)
您好尝试设置对Outlook库和此代码的引用
您可以通过查看此Article来查看如何添加对库的引用。我在您的代码中看到的是您使用的是Outlook常量,我不确定您是否使用了早期绑定,因此代码无法识别常数的正确值。
如果您查看此link,您会看到变量“olBusy”的值为2,“olFree”的值为0;也许代码不理解变量并给它一个默认的int值0(自由状态)
Option Explicit
Function SendMeetingRequest(subject As String, _
location As String, _
startDateTime As Date, _
durationMinutes As Integer, _
associateEmail As String, _
branchManagerEmail As String, _
allDayEvent As Boolean) As Boolean
Dim myOutlook As Outlook.Application
Dim myApt As AppointmentItem
Dim r As recipient
我希望这会有所帮助。
On Error GoTo ErrorHandler
SendMeetingRequest = True
' Create the Outlook session
Set myOutlook = New Outlook.Application
Set myApt = myOutlook.CreateItem(olAppointmentItem) ' Set the appointment properties
Set r = myApt.Recipients.Add(associateEmail)
r.Type = OlMeetingRecipientType.olRequired
Set r = myApt.Recipients.Add(branchManagerEmail)
r.Type = OlMeetingRecipientType.olOptional
With myApt
.subject = subject
.location = location
.Start = startDateTime
.Duration = durationMinutes
.MeetingStatus = olMeeting
.allDayEvent = allDayEvent
.BusyStatus = olBusy
.ReminderSet = False
.Save
.send
End With
Exit_Handler:
Exit Function
ErrorHandler:
MsgBox Err & ": " & Error(Err)
SendMeetingRequest = False
Resume Exit_Handler
End Function