Outlook Addin: Updating AppointmentItem.Body breaks the RTFBody - outlook-addin

In my Outlook addin I update the RTFBody (using WordEditor) and the Body of the AppointmentItem. After calling Save() on myAppointmentItem the layout shows broken for an rich text Appointment in Outlook. How can I prevent this from happening.
Obviously the ApppointmehtItem contains data in both places (RTFBody AND Body). Changing only one seems wrong to me. Any advice?

The Body property is a plain text representation of the RTFBody property. If you set the RTFBody property there is no need to set the plain text, it is done automatically. That is how Outlook syncs body-related properties.
Don't forget to call the Save method to apply your changes to make properties synced.

Related

Add a hidden tag to outgoing mail

I create a mail by VBA when sending invoices and automated newsletters by Outlook (2019).
For reimporting the mails from the Sent folder into the database it would be convenient to read a hidden tag including the customer number which I would like to embed into the mail.
You can add a custom property either using MailItem.UserProperties.Add or by setting your custom property directly using MailItem.PropertyAccessor.SetProperty.
Keep in mind adding a user property can force Outlook to send in the RTF format (the infamous winmail.dat attachment), so the latter solution is preferable. You just need to make sure you get the DASL property name (to be used with MailItem.PropertyAccessor.SetProperty) right. You can use the former approach (MailItem.UserProperties.Add), take a look at the message in the Sent Items folder with OutlookSpy (I am its author - click IMessage button), then use the DASL property name replacing MailItem.UserProperties.Add with MailItem.PropertyAccessor.SetProperty

VSTO Outlook AddIn: How to handle event when AppointmentItem.Body changes

I tried to catch the event when the AppointmentItem.Body changes. Handling the PropertyChange on the AppointmentItem does not get called when I type in text or save the AppointmentItem. It gets called when I hit the button "Add Participants though".
Best would be to get the Keydown on the body editor?
The Outlook object model may not propagate changes made in the Outlook UI until you switch focus to another field and/or save the item. This is a well-known issue when dealing with the Outlook object model.

VSTO Outlook Plugin updates Appointment.Body and thus Outlook shows text instead of html part of multipart message

I receive multipart invitations which include calendar and text and html part. When I open those invitation mails in outlook it shows the html part.
Now my code updates the text part with:
myAppointment.Body = myAppointment.Body.Replace(OutlookAddIn4.Resources.Resources.LinkToMeeting + " " + meetingLink, "");
myAppointment.Save();
This text is normally NOT included in the text part. Therefore this call DOES NOT change anything.
Although Outlook now shows the text part instead of the HTML part.
My questions:
1.) How can avoid this?
2.) Is there a chance to determine in my Plugin whether Outlook shows the html part (RTFBody that is, right) or the text part?
Thanks
Hannes
Firstly, before unconditionally resetting the body, check if there is something to replace and only then do anything.
Secondly, you can take a look at the RtfBody property and set it instead. If HTML is used, RTF will have the "\fromhtml" header. Latest versions of Outlook support HTML, but HTMLBody property has not been added to the AppointmentItem object. In theory, you can set the PR_HTML property, but PropertyAccessor.SetProperty won't let you set it. If using Redemption is an option (I am its author), you can either set the RDOAppointment.HTMLBody property or set PR_HTML.

Handling save event in Outlook

Good morning, I need my VBA code to run right before the TaskItem is saved, is there any way I can handle the event of saving ? I cannot find anything I could use in documentation. I am using MS-Office 2010.
Edit: I have tried
Private Sub TaskItem_Quit()
The macro disappears from macro list, but the code still does not run.
Try the Write event.
https://msdn.microsoft.com/en-us/library/office/ff868664.aspx
"Occurs when an instance of the parent object is saved, either explicitly (for example, using the Save or SaveAs methods) or implicitly (for example, in response to a prompt when closing the item's inspector)."

Outlook Appointment Item: Set the "Label"

In Outlook 2003, when you have a calendar event, it has an option to set its Label to Important, Business, Personal, etc, each having a different colour. This colour will be the colour of the scheduled event on your calendar.
My problem is I have no idea how to change it using an AppointmentItem. I've looked through the object browser and see nothing that looks like it relates to changing the label/colour. I'm accessing Outlook through an Access module, and have code set up to change the object's subject etc.
So what I want to know is, is there a way to change the events label/colour through an appointmentItem? And if so, how?
The term you are looking for is the item's Category. You can modify it using the Categories property on the AppointmentItem object. It's a string, so you can simply put the value you want in there.
The color displayed is customizable by the user, so you are better off just setting the label name and not try to put a specific color for the appointment.
VBA has no way to set the label color. You would need CDO for this. See http://www.outlookcode.com/codedetail.aspx?id=139 for sample code.