Solved

Outlook rule stops running VBScript after reboot

Posted on 2007-04-11
5
783 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:irvcon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:irvcon
ID: 18927807
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
 
LVL 76

Expert Comment

by:David Lee
ID: 19012631
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
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 19153515
Recommend delete with no refund.
0
 

Author Comment

by:irvcon
ID: 19169837
It turned out to be the macro security settings in Outlook.  Thanks for the assist BlueDevilFan
0

Featured Post

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question