Discussion:
How to format (html) appointment body? Outlook VSTO
(too old to reply)
musa.biralo
2010-05-02 11:44:14 UTC
Permalink
Hi,

I am trying to create a formatted appointment body but the only method
I can see in the appointmentItem is body. This method only writes the
plain text not the formatted html body.

what i simply like to do is
appointmentItem.HTMLBody = emailItem.HTMLBody

but the HTMLBody is not availabe under AppointmentItem :(

So, what is the approach of formatting an appointment body?

Thank you.
musa.biralo
2010-05-02 13:38:19 UTC
Permalink
Looks like this is the only method.... but i am stuck at another
simple issue :(


Dim appointmentItem As Outlook.AppointmentItem =
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olAppointmentItem)
CopyEmailBodyToAppointmentBody(selectedMail, appointmentItem)

'--------------------



Private Function CopyEmailBodyToAppointmentBody(ByVal email As
Microsoft.Office.Interop.Outlook.MailItem, _
ByVal appointment As
Microsoft.Office.Interop.Outlook.AppointmentItem) As Boolean

If email Is Nothing OrElse appointment Is Nothing Then
Return False
End If

Try

Dim emailWordDocument As Microsoft.Office.Interop.Word.Document
= email.GetInspector.WordEditor
Dim emailWordSelection As
Microsoft.Office.Interop.Word.Selection =
emailWordDocument.Windows(1).Selection

Dim appointmentWordDocument As
Microsoft.Office.Interop.Word.Document =
appointment.GetInspector.WordEditor
Dim appointmentWordSelection As
Microsoft.Office.Interop.Word.Selection =
emailWordDocument.Windows(1).Selection

emailWordSelection.WholeStory()
emailWordSelection.Copy()


appointmentWordSelection.PasteAndFormat(Microsoft.Office.Interop.Word.WdRecoveryType.wdPasteDefault)
'<---- Error
' Error = This method or property is not available because the
document is locked for editing.
' I am clueless on resolving this. What do I need to do to
resolve this? Thanks.

Catch ex As Exception
Return False
End Try

Return True

End Function

Original Source Code : http://www.outlookcode.com/codedetail.aspx?id=2040

Thanks for your help.
Musa.
Post by musa.biralo
Hi,
I am trying to create a formatted appointment body but the only method
I can see in the appointmentItem is body. This method only writes the
plain text not the formatted html body.
what i simply like to do is
appointmentItem.HTMLBody = emailItem.HTMLBody
but the HTMLBody is not availabe under AppointmentItem :(
So, what is the approach of formatting an appointment body?
Thank you.
Ken Slovak - [MVP - Outlook]
2010-05-03 13:13:27 UTC
Permalink
There is no HTMLBody property because that type of item doesn't support
HTML. You can only provide formatting using RTF (Rich Text format) and
provide it in the PR_RTF_COMPRESSED property, which is a binary property
(you'd write to it as an array of hex coded bytes). The DASL property tag
for PR_RTF_COMPRESSED is
"http://schemas.microsoft.com/mapi/proptag/0x10090102".

You would have to create syntactically correct RTF text and write it to that
property. You may want to re-think your efforts, RTF is a real beast to work
with. Also, in Outlook 2007 the PropertyAccessor will be able to write that
property but won't be able to read it if the contents of the property are
larger than about 8 KB.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"musa.biralo" <***@gmail.com> wrote in message news:a7e76c13-d567-45bf-b70f-***@37g2000yqm.googlegroups.com...
Looks like this is the only method.... but i am stuck at another
simple issue :(


Dim appointmentItem As Outlook.AppointmentItem =
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olAppointmentItem)
CopyEmailBodyToAppointmentBody(selectedMail, appointmentItem)

'--------------------



Private Function CopyEmailBodyToAppointmentBody(ByVal email As
Microsoft.Office.Interop.Outlook.MailItem, _
ByVal appointment As
Microsoft.Office.Interop.Outlook.AppointmentItem) As Boolean

If email Is Nothing OrElse appointment Is Nothing Then
Return False
End If

Try

Dim emailWordDocument As Microsoft.Office.Interop.Word.Document
= email.GetInspector.WordEditor
Dim emailWordSelection As
Microsoft.Office.Interop.Word.Selection =
emailWordDocument.Windows(1).Selection

Dim appointmentWordDocument As
Microsoft.Office.Interop.Word.Document =
appointment.GetInspector.WordEditor
Dim appointmentWordSelection As
Microsoft.Office.Interop.Word.Selection =
emailWordDocument.Windows(1).Selection

emailWordSelection.WholeStory()
emailWordSelection.Copy()


appointmentWordSelection.PasteAndFormat(Microsoft.Office.Interop.Word.WdRecoveryType.wdPasteDefault)
'<---- Error
' Error = This method or property is not available because the
document is locked for editing.
' I am clueless on resolving this. What do I need to do to
resolve this? Thanks.

Catch ex As Exception
Return False
End Try

Return True

End Function

Original Source Code : http://www.outlookcode.com/codedetail.aspx?id=2040

Thanks for your help.
Musa.
Post by musa.biralo
Hi,
I am trying to create a formatted appointment body but the only method
I can see in the appointmentItem is body. This method only writes the
plain text not the formatted html body.
what i simply like to do is
appointmentItem.HTMLBody = emailItem.HTMLBody
but the HTMLBody is not availabe under AppointmentItem :(
So, what is the approach of formatting an appointment body?
Thank you.
muas
2010-05-03 16:23:41 UTC
Permalink
Thanks Ken for the reply.

From the post of Sue in http://www.outlookcode.com/codedetail.aspx?id=2040
it does not appear that it will be too hard.

The problem, i got stuck at is now little bit different:
Error = "This method or property is not available because the document
is locked for editing". Second post from bottom shows where this error
is coming from

How can I resolve this?
Thanks
Post by Ken Slovak - [MVP - Outlook]
There is no HTMLBody property because that type of item doesn't support
HTML. You can only provide formatting using RTF (Rich Text format) and
provide it in the PR_RTF_COMPRESSED property, which is a binary property
(you'd write to it as an array of hex coded bytes). The DASL property tag
for PR_RTF_COMPRESSED is
"http://schemas.microsoft.com/mapi/proptag/0x10090102".
You would have to create syntactically correct RTF text and write it to that
property. You may want to re-think your efforts, RTF is a real beast to work
with. Also, in Outlook 2007 the PropertyAccessor will be able to write that
property but won't be able to read it if the contents of the property are
larger than about 8 KB.
--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.http://www.slovaktech.com/products.htm
Looks like this is the only method.... but i am stuck at another
simple issue :(
Dim appointmentItem As Outlook.AppointmentItem =
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olAppointmentItem)
CopyEmailBodyToAppointmentBody(selectedMail, appointmentItem)
'--------------------
Private Function CopyEmailBodyToAppointmentBody(ByVal email As
Microsoft.Office.Interop.Outlook.MailItem, _
                      ByVal appointment As
Microsoft.Office.Interop.Outlook.AppointmentItem) As Boolean
    If email Is Nothing OrElse appointment Is Nothing Then
      Return False
    End If
    Try
      Dim emailWordDocument As Microsoft.Office.Interop.Word.Document
= email.GetInspector.WordEditor
      Dim emailWordSelection As
Microsoft.Office.Interop.Word.Selection =
emailWordDocument.Windows(1).Selection
      Dim appointmentWordDocument As
Microsoft.Office.Interop.Word.Document =
appointment.GetInspector.WordEditor
      Dim appointmentWordSelection As
Microsoft.Office.Interop.Word.Selection =
emailWordDocument.Windows(1).Selection
      emailWordSelection.WholeStory()
      emailWordSelection.Copy()
appointmentWordSelection.PasteAndFormat(Microsoft.Office.Interop.Word.WdRecoveryType.wdPasteDefault)
'<---- Error
      ' Error = This method or property is not available because the
document is locked for editing.
      ' I am clueless on resolving this. What do I need to do to
resolve this? Thanks.
    Catch ex As Exception
      Return False
    End Try
    Return True
  End Function
Original Source Code :http://www.outlookcode.com/codedetail.aspx?id=2040
Thanks for your help.
Musa.
Post by musa.biralo
Hi,
I am trying to create a formatted appointment body but the only method
I can see in the appointmentItem is body. This method only writes the
plain text not the formatted html body.
what i simply like to do is
appointmentItem.HTMLBody = emailItem.HTMLBody
but the HTMLBody is not availabe under AppointmentItem :(
So, what is the approach of formatting an appointment body?
Thank you.
Ken Slovak - [MVP - Outlook]
2010-05-03 17:54:49 UTC
Permalink
I saw that Word error message you posted about, as far as I know you can't
do anything about it. You might get additional information on bypassing the
error in a Word programming group. If you can't do anything about the
problem then you'd be stuck doing what I said.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"muas" <***@gmail.com> wrote in message news:ad17c3ed-c000-456e-ae3c-***@h9g2000yqm.googlegroups.com...
Thanks Ken for the reply.

From the post of Sue in http://www.outlookcode.com/codedetail.aspx?id=2040
it does not appear that it will be too hard.

The problem, i got stuck at is now little bit different:
Error = "This method or property is not available because the document
is locked for editing". Second post from bottom shows where this error
is coming from

How can I resolve this?
Thanks
Loading...