HTML olAppointment Body?

T

Tony Gravagno

Emails can have a body set to HTML (OlBodyFormat=olFormatHTML). All
of the examples I see for Outlook appointments have plain text. But
it's obvious that within an appointment we can use at least rich text.
Can we set olAppointment.Body with text as OlBodyFormat=olFormatHTML,
or is it sort of hardcoded as olFormatRichText?

I'm hoping we can use HTML with complex styles, images, etc.

Thanks.
 
S

Sue Mosher [MVP-Outlook]

Nope. Only MailItem and PostItem objects have an HTMLBody property. Appointment bodies are rich text, and that formatted content isn't exposed in the Outlook object model until Office 2007, where you can get at it indirectly through WordEditor. See http://www.outlookcode.com/d/formatmsg.htm for ideas for earlier versions.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
T

Tony Gravagno

Sue Mosher said:
Nope. Only MailItem and PostItem objects have an HTMLBody property. Appointment bodies are rich text, and that formatted content isn't exposed in the Outlook object model until Office 2007, where you can get at it indirectly through WordEditor. See http://www.outlookcode.com/d/formatmsg.htm for ideas for earlier versions.

As usual Sue, you're a gem!

Hmm, first on the Word method:
---------------
It seems with WordEditor that my code will still trigger security,
which I absolutely don't want.

I'm guessing the code would looks something like this:
olAppointmentItem myappt = myGetAppt()
olInspector objInsp = myappt.GetInspector()
Word.Document objDoc = objInsp.WordEditor

From there I'm wondering how I can convert the HTML into Doc format.
The only thing I can think of is to do something like this:
objDoc.SaveAs(
FileName:="trash.htm",
FileFormat:=Word.WdSaveFormat.wdFormatHTML
....
And then I should be able to load in the DHTML and "myappt.Save".

If that's the case it seems a little precarious. It also introduces
the overhead of loading Word on top of Outlook.
---------------

It looks like this is where I need to break from PIA and use
Redemption. I'm assuming the code will look something like this:
olAppointmentItem myappt = myGetAppt()
sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = myappt.GetInspector()
myHTMLeditor = sInspector.HTMLeditor

At this point I get lost for a couple reasons:
1) The online doc for Redemption doesn't document HTMLEditor.
http://www.dimastr.com/redemption/safeinspector.htm
2) Extrapolating from the doc that's there, I should be able to set a
..SelText or similar property, or maybe InnerHTML if going through the
DOM.
3) My code isn't running within the Outlook process, I've instantiated
from my own executable using PIA:
olapp = new PIA.Outlook.ApplicationClass();
Based on a comment on that help page for the RTFEditor, I'm not sure
which property is available for r/w of HTML text.
4) Just how sophisticated can the HTML be when using HTMLEditor? If
it doesn't process styles then I need to work something else out.

Now is probably a good time to actually load Redemption and maybe
OutlookSpy. :)

Thanks!!
 
S

Sue Mosher [MVP-Outlook]

You have Outlook 2007? And you're creating an addin? All Outlook objects should be derived from the Application object passed as part of the add-in architecture. The details depend on which architecture you're using -- shared add-in, VSTO, or VSTO SE. If you do that, then you won't have security prompts. Also, Outlook 2007 shouldn't give you security prompts even for external automation if the machine as up-to-date anti-virus protection ... unless the admin wants to leave the prompts in place.

With the WordEditor approach, you'd use Word methods to insert text, perform formatting, etc. on the objDoc variable you already have. Since Outlook 2007 uses Word for all editing, there is no overhead.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
T

Tony Gravagno

Sue Mosher said:
You have Outlook 2007? And you're creating an addin? All Outlook objects should be derived from the Application object passed as part of the add-in architecture. The details depend on which architecture you're using -- shared add-in, VSTO, or VSTO SE. If you do that, then you won't have security prompts. Also, Outlook 2007 shouldn't give you security prompts even for external automation if the machine as up-to-date anti-virus protection ... unless the admin wants to leave the prompts in place.

With the WordEditor approach, you'd use Word methods to insert text, perform formatting, etc. on the objDoc variable you already have. Since Outlook 2007 uses Word for all editing, there is no overhead.

I write some of my code as add-ins and then extract out the rules to
create standalone code, which is why for this project I'm not running
in-process. At the moment I am coding for O2003 with Exchange Server.
In short my client has a business application on a separate server
where triggers will send data updates to the Outlook Calendar and
Contacts for people in the field. The appointment updates are working
fine now except for this enhancement for formatted text.

This is the nature of most of my Office-related work. In another
thread we agreed that it was a bad idea to use Outlook as a server
(from a thick-app/tray/ or Windows Service), and yet that's where I
see so much value in this software. To me it's all about data, not
about user interfaces. I don't understand why for the last 8 years or
so Outlook and all MS Office apps have been so rigidly bound to the UI
in such a non-MVC manner. Anyway, I digress, sorry.

I can use the WordEditor approach with no problem but the source data
from the end-user was coming from the app as HTML with styles (yes,
perhaps another non-MVC problem that should be addressed). This
doesn't seem like a technically impossible task, and I'm hoping it can
be solved just for the coolness factor.

So does it seem reasonable to convert the HTML to Word format, or does
anyone have experience with using the HTMLEditor property of the
SafeInspector in Redemption for doing this sort of thing?

Thanks!
 
S

Sue Mosher [MVP-Outlook]

WordEditor won't help you with Outlook 2003 appointments and contacts. As I said earlier, it is relevant only to those item bodies in Outlook 2007. If you're using Outlook 2003, your best choice is to use Redemption's SafeInspector.

I don't know how useful it might be to your project, but one way to convert HTML to RTF is to open the HTML file in Word and save it as an ..rtf file.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top