简体   繁体   中英

Alternative to CommandBarControl for Outlook 2013 VSTO add-in

I have a small VSTO add-in that I've used with Outlook 2010 for some time. A move to Office 2013/Outlook 2013 is soon happening and so the add-in needs to be re-written to work with Outlook 2013.

The Outlook add-in is triggered by a custom ribbon button. When triggered, the add-in will create a new meeting request window and fill the message body with some custom content. After which the user can complete the meeting request and send it if they so desire.

The issue I'm currently having is that previously, this message window was created using the CommandBarControl object to programmatically trigger a click of the "New Meeting" button in Outlook. This worked in previous versions of Outlook, but I gather that the CommandBarControl object has been removed from Outlook 2013 and now fails silently. This is indeed what I am seeing.

The original code that was being used to create the new meeting request is this:

Explorer activeExplorer = Globals.ThisAddIn.Application.ActiveExplorer();

CommandBarControl commandBarControl = activeExplorer.CommandBars.FindControl(Type.Missing, 1106);
commandBarControl.Execute();

appointmentItem = (AppointmentItem)Globals.ThisAddIn.Application.ActiveInspector().CurrentItem;
appointmentItem.MeetingStatus = OlMeetingStatus.olMeeting;
appointmentItem.RTFBody = message; // message is a byte array being passed in from elsewhere.

The FindControl() method is used to find the "New Meeting" button in Outlook and then Execute() a click action on that button.

An alternative might be something like this:

appointmentItem = (AppointmentItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
appointmentItem.MeetingStatus = OlMeetingStatus.olMeeting;
appointmentItem.RTFBody = message; // message is a byte array being passed in from elsewhere.
appointmentItem.Display(false);

The second code block will also create a new meeting request window and works in Outlook 2013, however there are a couple of subtle but important differences with the second code block...

  1. The created meeting request will not inherit the date and time that a user has previously clicked on in their calendar, instead it will default to the current date/time regardless of what date/time the user has clicked on in their calendar.
  2. The created meeting request will not respect the situation where a user is creating a meeting request "on behalf of" another user, because it ignores which calendar has been clicked on before the user initiated the new meeting request.

So my question is this: how can one now programmatically create (using a VSTO add-in) a new meeting request in Outlook 2013 that will respect which calendar the user has clicked on before hand? That is, it will satisfy the above two requirements that previously using the CommandBarControl object managed to satisfy?

You are right, Command bars were deprecated in Office 2010. Now the Fluent UI is used instead. You can read more about the new UI in the following series of articles:

You can run the required ribbon button programmatically using the CommandBars.ExecuteMso method (see the CommandBars property of the Explorer and Inspector classes). You just need to pass the idMso value of the built-in control you need to run. The following links provides lists of built-in controls for Office 2010 and 2013:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM