Add shape to Outlook 2003 mail

Add-in Express™ Support Service
That's what is more important than anything else

Add shape to Outlook 2003 mail
Adding shape in NewInspector-event causes RPC_E_SERVERFAULT 
Jacob Vestergaard




Posts: 68
Joined: 2008-06-08
Hello,

I am trying to add a picture to a WordEditor-mail in outlook 2003 on the NewInspector event.
This, however, throws an exception when trying to use the .Shapes.AddPicture() method. It seems that the Word-document is not entirely loaded or something, when trying to access it. How to know when it is? This approach works fine when firing it from a button on an Inspector Commandbar, but throws the following exception when used in NewInspector-event:

Server produced an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))


I am using the following code:

Private Sub adxOutlookEvents_NewInspector(ByVal sender As Object, ByVal inspector As Object, ByVal folderName As String) Handles adxOutlookEvents.NewInspector
        Dim insp As Outlook.Inspector = Nothing
        Dim mailItem As Outlook.MailItem = Nothing
        Try
            insp = CType(inspector, Outlook.Inspector)

                If insp.EditorType = Outlook.OlEditorType.olEditorWord Then
                    Dim doc As Word.Document = Nothing
                    Dim pic As Word.Shape = Nothing
                    Try
                        doc = CType(insp.WordEditor, Word.Document)
                        pic = doc.Shapes.AddPicture("C:image.jpg", False, True, Word.WdShapePosition.wdShapeRight)
                    Catch ex As Exception
                        MsgBox("NewInspector >> Error: " & ex.Message)
                    Finally
                        pic = Nothing
                        doc = Nothing
                    End Try
                End If
        Catch ex As Exception
            ErrHandler("NewInspector", ex)
        End Try
    End Sub


Thanks in advance,
Jacob S. Vestergaard
Posted 05 Sep, 2008 06:53:45 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Jacob,

Please read the following topic.
.NET, Extended MAPI, Windows Phone & RT
Posted 05 Sep, 2008 15:47:44 Top
Jacob Vestergaard




Posts: 68
Joined: 2008-06-08
Hi Eugene,

That approach is not ideal, when Word is set as the editor, because:

1) Modifying the .Htmlbody causes commandbar-flicker.
2) Gmail still doesn't display images attached that way properly (See this thread)
3) The approach mentioned above works perfect, when clicking the button (smooth display, correct aligment of mouse and so on), which is why I would like to at least utilize the Word.Document-approach.

I hope you can follow my reasoning. I will try with your suggested approach once more, but I sincerly hope you can help me with the above approach.

Thank you once again,
Jacob
Posted 05 Sep, 2008 16:31:31 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Jacob,

It seems that the Inspector window is not initialized yet. You cannot use this code in the NewInspector event handler.
.NET, Extended MAPI, Windows Phone & RT
Posted 08 Sep, 2008 10:20:13 Top