Message Rule Does Not Run VBA Procedure

L

Lowell

Created a message rule to check for a message with an attachment from a
specific sender. I set the rule to run a procedure I had created based on
info I saw here and elsewhere. Everything worked fine initially. It even
worked on a friend's PC, for whom I created the procedure.

A day or two later, friend notifies me that nothing works. Checked my system
and found the same. We have both recreated the message rule and reset it to
the procedure. No go.

The procedure is below. The first two lines after the Dim statements were
commented out initially and everything worked. Since the failure, we both
have uncommented the two lines, one at a time, to see if they were the source
of the problem. I set a a toggle break point, sent myself a message meeting
the rule's requirements, and the procedure was never accessed by the rule.
What am I missing?

Public Sub SaveAttachment(MyMail As MailItem)
Dim MyAttachment As Object
Dim MyOlApp As Object



'Set MyOlApp = CreateObject("Outlook.Application")
'Set MyMail = MyOlApp.ActiveInspector.CurrentItem
Set MyAttachment = MyMail.Attachments
MyAttachment.Item(1).SaveAsFile "C:\Documents and Settings\LB\My
Documents\temp\" & _
MyAttachment.Item(1).DisplayName

Exit Sub
End Sub
 
S

Sue Mosher [MVP-Outlook]

Does other VBA code, such as a simple MsgBox "Hello" procedure run? Did you check the setting in Tools | Macro | Security? Does it work if you rewrite it to use the intrinsic Application object and get the message from its EntryID, as in:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' do stuff with olMail, e.g.
MsgBox olMail.SUbject

Set olMail = Nothing
Set olNS = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Michael Bauer

Am Sun, 5 Mar 2006 13:42:27 -0800 schrieb Lowell:

Please see click the menu bar: ?/Info, then the "Deactivated Items" button
(or something similar).

If VBA is listed there then re-activate it.
 
L

Lowell

Michael - I'm not quite following your post. Sorry.

The menu bar - is it the one in the VB editor window or the normal Outlook
menu bar? The only question mark item I see on either menu bar activates
Help. I can't find anything showing Info or Deactivated Items. Can you give
me a little more help?

Thanks,
Lowell
 
L

Lowell

I found the problem, at least on my PC, and just came back to post it and saw
your post, Sue. You were right on. Somehow, my Security setting had gotten
changed to High, so all macros were disabled. I got an error message (macros
disabled) when I tried to run a simple MsgBox procedure. Thanks.
 
M

Michael Bauer

Am Mon, 6 Mar 2006 05:10:52 -0800 schrieb Lowell:

I didn´t saw Sue´s answer as I wrote mine and I think the problem is solved
know, right?

To answer the new question: It´s the menu bar in Outlook, not in the VBA
editor. It´s possible that there´s no "Info" button in the ? menu. In German
the button is called "Info", I don´t know the name for English Systems.
Also, maybe you need to expand the menu first (not used buttons are hidden)
by clicking in the last entry.

Sorry, know I remember, Is the button called "About..."?

"Deactivated Items" or "Deactivated Elements" (that translation I really
don´t know) is available in Outlook >= 2002 only.
 
S

Sue Mosher [MVP-Outlook]

In English, it would be the Help | About Microsoft Outlook command.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lowell

Michael,

Yes the problem is solved, I think. However, I noticed some odd behavior
after the macro began working again. When I left my PC inactive long enough
for the password protected screen saver to activate, I would find the VB
Editor window open to my macro when I entered my password and began using the
PC again. The odd thing is the editor window would have no menu or toolbars!

I am monitoring that situation now. I have disabled my screen saver, to
determine if that is the cause or if just receiving new messages is the
cause. Will keep you posted.

Thanks again for your help.

Lowell
 
M

Michael Bauer

Am Tue, 7 Mar 2006 07:47:42 -0500 schrieb Sue Mosher [MVP-Outlook]:


In English, it would be the Help | About Microsoft Outlook command.

Thanks, Sue.
 
L

Lowell

More trouble. This morning, I tested my rule/macro again. Nothing worked. Got
an error message saying the script did not exist. Went into VB Editor and the
whole project, module, and code are gone. Most options on the menus are
unavailable, except for a few things on the Format, View and Tools menu. I
cannot create a new project or module. My security level is still set on
medium and I have checked the Help/About/Disabled items - nothing is disabled.

Any ideas on what has happened. It appears I've totally lost VB capability
within Outlook. Still have it in Excel/Word.
 
L

Lowell

Forgot to include this. After opening Outlook and on first attempt to access
the VB Editor, I get popup asking if I want to Disable/enable macros. This
dialog includes the project name under whihc I created the macros. Clicking
Enable results in File Not Found error being displayed. Close that dialog and
then get to the VB Editor with the problems mentioned in previous post.
 
S

Sue Mosher [MVP-Outlook]

My experience is that the VBAProject.OTM file can be a little fragile, especially if you're using "run a script" rules. The way to back up your modules is to export them.

You could try changing the security setting to Low to see if that helps the file recovery, but I fear it may be totally corrupted, in which case the cure would be to shut down Outlook, rename VBAProject.OTM, then restart Outlook and let Outlook create a new, clean, empty one.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lowell

Sue - That worked. However, instead of having VBAProject.OTM in the Project
Explorer pane of VB Editor, I now have an item named Project 1. Should I
rename it to VBAProject.OTM?
 
S

Sue Mosher [MVP-Outlook]

The file *is* named Vbaproject.otm. The project name doesn't matter.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lowell

You want to know what's weird? After I renamed the original Vbaproject.otm
and got everything working again, there is not a new Vbaproject.otm in the
same folder as the one I renamed. I haven't found it (the new one) yet. Is
there a set location where this file is stored?
 
S

Sue Mosher [MVP-Outlook]

It's always in the same location, in your Windows profile folders. You won't see it if you don't have hidden/system items turned on.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lowell

I searched and did not find it. My folder options are set to show hidden
files. I let the system search in the C:\Document and Settings folder, which
is where the user profiles are stored. I'm going to search the whole hard
disk. this is getting a little creepy, since I found the corrupted file and
can't find the newly generated one.

lowell
 
L

Lowell

Sue - just wanted to say thanks one more time for your help. With this new
installation of the rule/macro, things seem much more stable. I'm not geting
that VB editor window with no menus/toolbars mysteriuosly popping up this
time. Maybe we've gotten this one handled.

Again, thank you.
Lowell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top