vba 如何在 Outlook.AppointmentItem 中设置 Recipients 属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19595434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i set Recipients property in Outlook.AppointmentItem?
提问by devutkarsh
In this excel VBA code i am trying to create a new appointment in outlook and what i want is to email that appointment i.e. i want to invite users for the appointment.
I am not sure if i need to create a new outlook.recipients object for this thing or i am not using the .Recipeint.Add property properly.
在这个 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 ("[email protected]") ' This line is not working
' .Display
.Send
End With
End Sub
I am getting application-defined or object defined as error. Thanks in advance.
我将应用程序定义或对象定义为错误。提前致谢。
回答by JimmyPena
Appointments are personal and for you only.
约会是个人的,仅供您使用。
You have to change it to a meeting first before you can add recipients.
您必须先将其更改为会议,然后才能添加收件人。
To do so, add AppointmentItem.MeetingStatus = olMeeting
to your code. So for your code it would be
为此,请添加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 ("[email protected]") ' This line is not working
' .Display
.Send
End With
End Sub
回答by rory.ap
Are you getting a pop-up like this?
你会收到这样的弹出窗口吗?
If so and if you are clicking "Deny", then that could explain your error. This happens because the object model guard is put in place to prevent hackers from gaining access to your email recipients through the outlook object model. See this article:
如果是这样并且如果您单击“拒绝”,则可以解释您的错误。发生这种情况是因为设置了对象模型保护以防止黑客通过 Outlook 对象模型访问您的电子邮件收件人。看这篇文章:
http://msdn.microsoft.com/en-us/library/office/ff864479%28v=office.14%29.aspx
http://msdn.microsoft.com/en-us/library/office/ff864479%28v=office.14%29.aspx