2

在这个 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

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

4

2 回答 2

3

约会是个人的,仅供您使用。

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

为此,请添加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
于 2013-10-25T17:00:41.903 回答
0

你有这样的弹出窗口吗?

在此处输入图像描述

如果是这样并且如果您单击“拒绝”,那么这可以解释您的错误。发生这种情况是因为设置了对象模型保护以防止黑客通过 Outlook 对象模型访问您的电子邮件收件人。见这篇文章:

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

于 2013-10-25T17:15:49.440 回答