1

I have a rule launching a VBA macro in Outlook (Office 365). The macro is activated when an email arrives on one of the Exchange accounts configured in the profile. It is used to sort the email that has arrived.

Sometimes the rule crashes. The On Error does not catch the error.

An alert popup appears saying:

Unexpected error

It seems that the macro doesn't run in that case.

If in the rule I insert the condition "interrupt the other rules", then it remains active otherwise it is deactivated automatically.

The code under ThisOutlookSession.cls:

Public Sub MySort(Item As Object)
  Dim Msg As Outlook.MailItem
  On Error GoTo ErrorHandler:
  If TypeName(Item) = "MailItem" Then
     MyMove Item
  End If
ErrorHandler:
  Err = 0
  Exit Sub
End Sub

Sub MyMove(ele As Object)
[...]
  ele.Move 
[...]
End Sub

I noticed in rules and alerts management I no longer see my macro in the scripts.

Community
  • 1
  • 1
Fu-rio
  • 11
  • 2
  • Run a script is unreliable. You could convert to ItemAdd. [How do I trigger a macro to run after a new mail is received in Outlook?](https://stackoverflow.com/a/11267757/1571407) and [Get reference to additional Inbox](https://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton Aug 17 '23 at 15:06

1 Answers1

0

Fixed!

I passed parameter by reference.

Public Sub MySort(byref Item As Object)
[...]
Sub MyMove(byref ele As Object)
[...]
Fu-rio
  • 11
  • 2