Outlook rule stops running VBScript after reboot

I have a VBScript that creates a task using an incoming email in outlook.  There's a rule for incoming mail that triggers the script if the email contains a certain word in the subject, and moves it to a "Processed" folder to show that it's been handled.

Occasionally the VBScript portion of this setup stops working.  The outlook rule still recognizes the emails and moves them to the "Processed" folder, but the VBScript does nothing.  Things that seem to break it are closing and opening outlook...but only about half the time.  The one thing that breaks it reliably is logging off that account and logging back on.

The way i fix it is by removing or renaming the VbaProject.OTM file, opening the VBScript editor through outlook, and pasting in the same old code i had previously.  The script will then work great until the next reboot/logoff/random disruption.

What's breaking my code!?  It's driving me nuts because my company relies on this script, and it dies without warning every once in a while, keeping us all on our toes.  Any ideas are welcomed...thanks.

My problem is very similar to this one: http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_20703945.html?sfQueryTermInfo=1+disabl+macro+outlook

But the solution that works for them, doesn't work for me (long term).

Here's a copy of my code:

Sub MakeTaskFromMail2(MyMail As Outlook.MailItem)
    Dim strID As String
    Dim olNS As Outlook.NameSpace
    Dim olMail As Outlook.MailItem
    Dim objTask As Outlook.TaskItem
   
    Dim preTaskSubject As String
    Dim taskSubject As String
    Dim taskDate As String
    Dim subjLength As Integer
   
    strID = MyMail.EntryID
    Set olNS = Application.GetNamespace("MAPI")
    Set olMail = olNS.GetItemFromID(strID)
    Set objTask = Application.CreateItem(olTaskItem)
   
    subjLength = Len(olMail.Subject)
    subjLength = subjLength - 6
    preTaskSubject = Right$(olMail.Subject, subjLength)
    taskSubject = Right$(preTaskSubject, subjLength - 9)
    taskDate = Left$(preTaskSubject, 8)
   
   
    With objTask
        .Subject = preTaskSubject
'       .StartDate = olMail.SentOn
        .Body = olMail.Body
    End With
    Call CopyAttachments(olMail, objTask)
    objTask.Save
   
    Set objTask = Nothing
    Set olMail = Nothing
    Set olNS = Nothing
End Sub
irvconAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

irvconAuthor Commented:
HELP!

Why does my code stop working after i close and reopen outlook?  After further investigation of this thread:

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_20703945.html?sfQueryTermInfo=1+disabl+macro+outlook

I once again tried renaming things, in all different orders, and all different ways without any success.  Logging out still kills the script.

The problem is not with getting the rule to run in outlook, but with where the rule triggers the script.  It never fails to move things to a processed folder, it only fails to actually run the code it's supposed to.
0
David LeeCommented:
Hi, irvcon.

The behavior you've described is deinitely strange.  I do see some potential problems with the code you posted, one in particular that might explain what's going on.  Before I advance a theory though I'd like to try a revised version of the code to see if I'm even close to having this figured out.  Can you try this version out and let me know if it makes any difference?

Sub MakeTaskFromMail2(MyMail As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Dim preTaskSubject As String
    Dim taskSubject As String
    Dim taskDate As String
    Dim subjLength As Integer
   
    Set objTask = Application.CreateItem(olTaskItem)
   
    subjLength = Len(MyMail.Subject) - 6
    preTaskSubject = Right$(MyMail.Subject, subjLength)
    taskSubject = Right$(preTaskSubject, subjLength - 9)
    taskDate = Left$(preTaskSubject, 8)

    With objTask
        .Subject = preTaskSubject
'       .StartDate = MyMail.SentOn
        .Body = MyMail.Body
    End With
    Call CopyAttachments(MyMail, objTask)
    objTask.Save
   
    Set objTask = Nothing
End Sub
0
David LeeCommented:
Recommend delete with no refund.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
irvconAuthor Commented:
It turned out to be the macro security settings in Outlook.  Thanks for the assist BlueDevilFan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.