我想添加C#代码(在我的Outlook VSTO Addin中)来创建约会并在显示时显示Schedule Assistant视图。
以下是我到目前为止编写的代码,它创建了一个约会,添加了收件人。但是当调用Display方法时,它会显示默认的Appointment视图。我希望它显示Schedule Assistant视图并显示我刚刚添加的收件人。
AppointmentItem newAppointment = Application.CreateItem(OlItemType.olAppointmentItem);
Recipients sentTo = newAppointment.Recipients;
Recipient sentInvite = null;
sentInvite = sentTo.Add(emailAddress);
sentInvite.Type = (int)OlMeetingRecipientType.olRequired;
sentTo.ResolveAll();
newAppointment.Display();
更新
在我的VSTO加载项项目中,我添加了一个UserControl。在这个UserControl中我有一个Button控件。单击按钮时,它将运行以下代码:
AppointmentItem newAppointment = Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
newAppointment.MeetingStatus = OlMeetingStatus.olMeeting;
Inspector inspector = newAppointment.GetInspector;
CommandBarControl commandBarControl = inspector.CommandBars.FindControl(Type.Missing, 14935);
commandBarControl.Execute();
Recipients recipients = newAppointment.Recipients;
Recipient readyByRecipient = null;
readyByRecipient = recipients.Add(emailAddress);
readyByRecipient.Type = (int)OlMeetingRecipientType.olRequired;
recipients.ResolveAll();
newAppointment.Display();
Marshal.ReleaseComObject(readyByRecipient);
Marshal.ReleaseComObject(recipients);
Marshal.ReleaseComObject(newAppointment);
当我调用FindControl方法(从OutlookAppointmentItemControls.xlsx文件传递ID值)时不幸,它返回null,因此我无法调用commandBarControl.Execute()
来显示Schedule Assistant视图。
我也尝试在调用newAppointment.Display()
后调用FindControl方法,但它仍然返回null。
答案 0 :(得分:1)
在调用Display方法之前,需要将AppointmentItem类的MeetingStatus属性设置为 olMeeting 值。例如:
Sub CreateAppt()
Dim myItem As Object
Dim myRequiredAttendee, myOptionalAttendee, myResourceAttendee As Outlook.Recipient
Set myItem = Application.CreateItem(olAppointmentItem)
myItem.MeetingStatus = olMeeting
myItem.Subject = "Strategy Meeting"
myItem.Location = "Conference Room B"
myItem.Start = #9/24/2015 1:30:00 PM#
myItem.Duration = 90
Set myRequiredAttendee = myItem.Recipients.Add("Nate Sun")
myRequiredAttendee.Type = olRequired
Set myOptionalAttendee = myItem.Recipients.Add("Kevin Kennedy")
myOptionalAttendee.Type = olOptional
Set myResourceAttendee = myItem.Recipients.Add("Conference Room B")
myResourceAttendee.Type = olResource
myItem.Display
End Sub
要查看“计划助手”视图,您可以以编程方式运行功能区上的相应按钮。 CommandBars类的Execute方法可用于运行Scheduling按钮。您只需要传递内置控件的idMso。有关实际值,请参阅Office 2013 Help Files: Office Fluent User Interface Control Identifiers。
答案 1 :(得分:0)
搞定了。解决方案是使用OutlookAppointmentItemControls.xlsx文件中的Control Name值调用ExecuteMso方法。如果在调用Display方法后调用ExecuteMso,它似乎才有效。
以下是与收件人一起创建新约会(会议)的代码,并在“检查器”窗口中显示“计划助手”视图。
AppointmentItem newAppointment = Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
newAppointment.MeetingStatus = OlMeetingStatus.olMeeting;
Recipients recipients = newAppointment.Recipients;
Recipient readyByRecipient = null;
readyByRecipient = recipients.Add(emailAddress);
readyByRecipient.Type = (int)OlMeetingRecipientType.olRequired;
recipients.ResolveAll();
newAppointment.Display();
Inspector inspector = newAppointment.GetInspector;
inspector.CommandBars.ExecuteMso("ShowSchedulingPage");
Marshal.ReleaseComObject(readyByRecipient);
Marshal.ReleaseComObject(recipients);
Marshal.ReleaseComObject(newAppointment);
Marshal.ReleaseComObject(inspector);