如何在Outlook.AppointmentItem中设置“收件人”属性?

时间:2013-10-25 16:52:29

标签: excel vba excel-vba outlook

在这个excel VBA代码中,我正在尝试在Outlook中创建一个新的约会,我想要的是通过电子邮件发送该约会,即我想邀请用户进行预约。
我不确定是否需要为此事创建一个新的outlook.recipients对象,或者我没有正确使用.Recipeint.Add属性。

Sub app()

    Dim OutApp As Outlook.Application 
    Dim OutMail As Outlook.AppointmentItem 

    Set OutApp = New Outlook.Application
    Set OutMail = OutApp.CreateItem(olAppointmentItem)

    With OutMail

       .Location = " happening"
       .Subject = " Event check "
       .Start = "8:00 PM" & Format(Date)
       .End = "9:00 PM" & Format(Date)
       .Body = "this is event details"
       .Recipients.Add ("someone@gmail.com") ' This line is not working
      ' .Display
       .Send

    End With

End Sub

我将应用程序定义或对象定义为错误。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

约会是个人的,仅限于您。

在添加收件人之前,您必须先将其更改为会议。

为此,请在代码中添加AppointmentItem.MeetingStatus = olMeeting。所以对于你的代码来说,它将是

Sub app()
Dim OutApp As Outlook.Application 
Dim OutMail As Outlook.AppointmentItem 

Set OutApp = New Outlook.Application
Set OutMail = OutApp.CreateItem(olAppointmentItem)

With OutMail
   .MeetingStatus = olMeeting
   .Location = " happening"
   .Subject = " Event check "
   .Start = "8:00 PM" & Format(Date)
   .End = "9:00 PM" & Format(Date)
   .Body = "this is event details"
   .Recipients.Add ("someone@gmail.com") ' This line is not working
  ' .Display
   .Send

End With
End Sub

答案 1 :(得分:0)

你有这样的弹出窗口吗?

enter image description here

如果是,如果您点击"拒绝",那么这可以解释您的错误。发生这种情况是因为对象模型防护装置已经到位,以防止黑客通过Outlook对象模型访问您的电子邮件收件人。看到这篇文章:

http://msdn.microsoft.com/en-us/library/office/ff864479%28v=office.14%29.aspx