HtmlBody problem's

Scenario :

VS2005
OUTLOOK 2003

inside a MailItem I have a commandbar with a button.
this button have the following code on click event :

Private Sub _mailButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles _mailButton.Click

Dim posizioneBody As Integer = m_olMailItem.HTMLBody.IndexOf("<body")
Dim posizioneChiusuraBody As Integer = m_olMailItem.HTMLBody.IndexOf(">",
posizioneBody)
m_olMailItem.HTMLBody = m_olMailItem.HTMLBody.Insert(posizioneChiusuraBody +
1, "SOMETHING")

End Sub

the first time that I click the button, the code work fine, so the bodyHtml
change in the MailItem.
from now the button finish to work, so if I click on it nothing happend.

but,
if I change my code with a sample MSGBOX, the button work all the time.....

What I am mistaking


Answer this question

HtmlBody problem's

  • VikasChandVerma

    Hi

    Your code looks fine but there are quirky OOM "Outlook Object Model" issues with working with HTML Body properties. Are there any errors being raised that you have captured elsewhere in your coding "On Error Resume Next" style coding. Often Outlook raises an Invalid Operation error when working with large email bodies and some malformed HTML in my expierience, have you tried on simpler emails and or different based emails.

    I presume you are looking to adjust the HTML Representation.

    Regards

  • Daniel Schloser

    IMO, your code looks like correct, so I don't know why it work only the first time....

    Maybe it's a problem with the text that you insert in your HTMLBody


    Hopes this help.

    Bye.

  • amitsingh18

    Hi Mike,
    I am using VS2005 + VSTO, so my code us try-catch system, no errors.


  • thebavarian

    Giuseppe,

    Mi piace di vedere gli italiani qui. Dobbiamo forse parlere in italiano!

    Allora,

    I added this little macro to my otm, and it works as expected every time. I am thinking that your HTMLBody is getting scrambled with the wrong info, and Outlook can't make sense of it the second time. Try my code, and see if this helps you make some progress. Let me know how it goes!

    Private item As mailItem
    Private Sub setit()
    Set item = Application.CreateItem(olMailItem)
    End Sub
    Private Sub addHTML()
      Dim iposb As Integer
      Dim ipose As Integer
     
      Dim strBegin As String
      Dim strEnd As String
     
      If item.BodyFormat = olFormatHTML Then
        strBegin = item.HTMLBody
        strEnd = strBegin
        ipose = InStr(iposb, strEnd, "</BODY>")
       
        strBegin = Mid(strBegin, 1, ipose)
        strBegin = strBegin & "new text" & vbCrLf
        strEnd = Mid(strEnd, ipose, Len(Mid(strEnd, ipose)))
       
        item.HTMLBody = strBegin & strEnd
        MsgBox item.HTMLBody
        End If

    End Sub

    John.



  • Doriak

    Is the click event firing on the second occasion Has the eventhandler been trashed :(

  • HtmlBody problem's