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

在这个优秀的VBA代码,我试图在Outlook中创build一个新的约会,我想要的是通过电子邮件的约会,即我想邀请用户的约会。
我不知道是否需要为这个东西创build一个新的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 

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

约会是个人的,只为你。

您必须首先将其更改为会议,然后才能添加收件人。

为此,请将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 

你有这样的popup窗口吗?

在这里输入图像说明

如果是这样,如果你点击“拒绝”,那么可以解释你的错误。 发生这种情况的原因是,对象模型守护进入到位以防止黑客通过Outlook对象模型访问您的电子邮件收件人。 看到这篇文章:

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