I have an email message in my Inbox which contains an inline object (e.g., an image). I want to remove it, and insert text at the same point in the email.
I tried wi
The WordEditor
basically is a word Document
if I remember correctly, so you should be able to do something similar to (tested in Word, may need tweak for Outlook), assuming an object variable like doc
to represent the Document
:
Revised & tested in Outlook 2010
Dim shp as InlineShape
Dim doc as Object `Word.Document
Dim shpRange as Object `Word.Range
Const wdInlineShapePicture as Long = 3
Const wdInlineShapesEmbeddedOLEObject as Long = 1
Set doc = objMsg.GetInspector.WordEditor
For Each shp In doc.InlineShapes
Select Case shp.Type
Case wdInlineShapePicture, wdInlineShapesEmbeddedOLEObject
'## Assign a range object with the text position of the shape
Set shpRange = doc.Range(shp.Range.Characters.First.Start, _
shp.Range.Characters.Last.End)
'## Replace the shape with text:
shpRange.Text = "Replacement Text"
Case Else
'## Do something else for other shape types, etc.
End Select
Next
Here is an example macro to process incoming mailitems, and replace the embedded images with text. Note the need to UnProtect
the document:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim arr() As String
Dim i As Integer
Dim m As MailItem
'## Word objects, using late-binding (or enable reference to MS Word)
Dim shp As Object 'Word.InlineShape
Dim doc As Object 'Word.Document
Dim shpRange As Object 'Word.Range
'## Establish some word constants for use with late-binding
Const wdInlineShapePicture As Long = 3
Const wdInlineShapeEmbeddedOLEObject As Long = 1
Const wdInlineShapeLinkedPicture As Long = 4
arr = Split(EntryIDCollection, ",")
For i = 0 To UBound(arr)
Set m = Application.Session.GetItemFromID(arr(i))
Set doc = m.GetInspector.WordEditor
doc.UnProtect
For Each shp In doc.InlineShapes
Select Case shp.Type
Case wdInlineShapePicture, _
wdInlineShapeEmbeddedOLEObject, _
wdInlineShapeLinkedPicture
'## Assign a range object with the text position of the shape
Set shpRange = doc.Range(shp.Range.Characters.First.Start, _
shp.Range.Characters.Last.End)
'## Replace the shape with text:
shpRange.Text = "Replacement Text"
Case Else
End Select
Next
Next
End Sub