Link to home
Start Free TrialLog in
Avatar of Tim Bouscal
Tim BouscalFlag for United States of America

asked on

Outlook VBA Errors and disables rule

This VB script looks at the begining of the subject and removes the mess that our IT dept adds to our email to notify us that the email came from an external source and should be handled with care.  Since I'm smart enough to do that without being reminded I personally want to remove that because an email conversation will end up with an additional string pre-pended to the subject line.    "RE: <EXT> Subject RE: <EXT> SubjectRE: <EXT> Subject RE: <EXT> Subject RE: <EXT> Subject RE: <EXT> Subject <EXT> Subject"  

Occasionally it throws an error that I haven't been able to trap and handle which causes the rule to be deactivated.  Any suggestions?

Sub Remove_EXT(myItem As MailItem)

    On Error GoTo Error_Handler
    
    Dim mySubject As String
    mySubject = myItem.Subject

If (Left(mySubject, 6)) = "<EXT> " Then
    mySubject = Right(mySubject, Len(mySubject) - 6)
End If

If (Left(mySubject, 5)) = "<EXT>" Then
    mySubject = Right(mySubject, Len(mySubject) - 5)
End If

If mySubject = "" Then
    Exit Sub
Else
       myItem.Subject = mySubject
       myItem.Save
End If

Exit Sub

Error_Handler:

    MsgBox "An error occurred" & vbCrLf & vbCrLf & "Error Number: " & Err.Number & vbCrLf & _
    "Error Source: RemoveExternalPrefix " & "Error Description: " & Err.Description, vbCritical, "An Error has Occured!"
    
End Sub

Open in new window

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

You have an error routine so what do you mean when you say "an error that I haven't been able to trap"?

BTW the error routine says "Error Source: RemoveExternalPrefix " which doesn't seem to be right since it's not the name of the procedure..
SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tim Bouscal

ASKER

Thanks guys, regarding trapping the error.  I don't get my message, I get a message from Outlook that has the 'unexpected error' msg that I loathe MS so much for.  Of course it's unexpected you fools! </rant>

I suspect Bill's suggestion of moving the message may be raising the error.  I'm going to look in to that and be back to close this out.