Home > Back-end >  outlook vba read mail RTFbody fails with error 'not implemented'
outlook vba read mail RTFbody fails with error 'not implemented'

Time:10-26

I have macro that reads Mail to generate a task with mail's content.

in few cases this hits problem, when reading the RTFbody from the mail, saying "not implemented".

I wonder if I can test against this? Similar like WHEN IS NULL ... allows to check if variable has appropriate content.

enter image description here

Sub CreateTempTaskFromMail()

Dim oMail As Outlook.MailItem
Set oMail = ActiveInspector.CurrentItem
    
Dim s, sNr As String
s = oMail.subject

Dim oTask As Outlook.TaskItem
Set oTask = CreateTaskWithTempFolder(s, False)  ' Function creating and returing task
    
oTask.RTFBody = oMail.RTFBody

End sub

CodePudding user response:

Before accessing the RTFBody property in the code I'd suggest checking the item's type first to make sure such property exists for a specific item type:

If TypeOf item Is MailItem Then
  ' do whatever you need with RTFBody here
End If

Or

If TypeName(item) = "MailItem" Then
 ' do whatever you need with RTFBody here
End If

CodePudding user response:

If there is absolutely no real solution then

Option Explicit

Sub CreateTempTaskFromMail()

Dim oObj As Object
Dim oMail As mailItem
Dim oTask As TaskItem

Dim s As String

Set oObj = ActiveInspector.currentItem

If oObj.Class = olMail Then

    Set oMail = oObj
    s = oMail.subject
    
    Set oTask = CreateTaskWithTempFolder(s, False)  ' Function creating and returing task
    
    ' If you absolutely cannot determine the problem
    ' https://excelmacromastery.com/vba-error-handling#On_Error_Resume_Next
    On Error Resume Next
    
    oTask.RTFBody = oMail.RTFBody
    
    If Err <> 0 Then
        Debug.Print "Error was bypassed using a technique that is to be avoided."
        Exit Sub
    End If
    
    ' Consider mandatory AND as soon as possible
    On Error GoTo 0
    
    oTask.Display

Else

    Debug.Print "not a mailitem"
    
End If

End Sub
  • Related