Run-time error '-2147221239 (80040109)

  • Thread starter Thread starter KdBrown
  • Start date Start date
K

KdBrown

A few months ago, I got some help writing the VBA to assign
categories to items in my inbox. Below is a sample of this
VBA.

Sub AssignMarketing()
'Assigns the selected email items to the MarketingCategory

Dim oSel As Outlook.Selection
Dim oMail As Object

Set oSel = Application.ActiveExplorer.Selection
For Each oMail In oSel
oMail.Categories = "Marketing"
oMail.Save
Next

However, I am getting run-time errors on this on a random
basis. The error is "Run-time error '-2147221239
(80040109)': The messaging interface has returned an
unknown error. If the problem persists, restart Outlook."

When I click on the Debug button in the message window, the
text "oMail.Save" is always highlighted.

If I close the Visual Basic Editor and try the macro again,
I may get the error or it may work. It appears to be
totally random. At first I thought it may be because I
still had the email or calendar item open, but that is not
always true.

Any help in solving this nagging problem would be greatly
appreciated.

Thanks,
KdBrown

End Sub
 
The first thing I would try here is to make sure the item
you're processing is actually an e-mail, as other types of
items can be present in Outlook folders. Try this:

Dim oSel As Outlook.Selection
Dim oMail As Object

Set oSel = Application.ActiveExplorer.Selection
For Each oMail In oSel
If oMail.Class = olMailItem Then
oMail.Categories = "Marketing"
oMail.Save
End If
Next


-Andrew
====================================
 
Back
Top