Solved

Outlook rule stops running VBScript after reboot

Posted on 2007-04-11
5
762 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now