VBA rules do nothing

  • Thread starter Thread starter Jeff Miller
  • Start date Start date
J

Jeff Miller

I get hundreds of emails a day on the webmaster account
that have their attachments blocked from Exchange. They
all have "Replaced * File.txt" attachments where * could
be Infected/Blocked (I'm not aware of any others.) I saw
some examples on the web for writing VBA with custom rules.

Here's what I wrote:
'---------------------------------------------------
Sub FilterJunk(objItem As MailItem)
If objItem.Attachments.Count > 0 Then
deleteMail = False
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = False
regEx.IgnoreCase = True
regEx.Pattern = "^Replaced \w+ File.txt"
For Each objAttach In objItem.Attachments
If regEx.Test(objAttach.FileName) Then
deleteMail = True
Exit For
End If
Next
Set regEx = Nothing
If deleteMail Then Call objItem.Delete
End If
Set objItem = Nothing
End Sub
'---------------------------------------------------

I can't see any problems based upon the code examples I've
seen out there. This should work. However, nothing happens
when I set up the rules wizard to run this code on my
local machine (no errors, nothing.)

So, I tried a simple test:
'---------------------------------------------------
Sub DoSomething(item As Object)
MsgBox "Something happened..."
End Sub
'---------------------------------------------------

Still, nothing.

My other rules work just fine (they just move mail to
various folders based upon e-mail addresses/subject
lines... nothing fancy requiring VBA.) Any help with this
problem would be appreciated.

~Jeff
 
This is in an Outlook 2002 or 2003 "run a script" rule? What condition(s)
are you using for the rule? Have you set a breakpoint to see if the code is
running at all?
 
-----Original Message-----
This is in an Outlook 2002 or 2003 "run a script" rule? What condition(s)
are you using for the rule? Have you set a breakpoint to see if the code is
running at all?

-----------

This is Outlook 2002 on Windows 2000 Professional.
The rule is:

Apply this rule after message arrives
on this machine only
run myProject.FilterJunk

I chose the rule from a list that has myProject.FilterJunk
and myProject.DoSomething (both in the original post.) I
have set a breakpoint in the Visual Basic Editor (Alt+F11)
by double clicking next to the first line of code and but
nothing happens when I send myself an e-mail with an
offender attachment or select and check the rule in the
Rules Wizard and run it ("Run Now...") against the list of
offending emails in my Inbox. A progress bar appears
momentarily which indicates that *something* is happening
but it appears the rule is not running at all since the
breakpoint is not hit. Can you think of a reason why it
wouldn't run or how to make it run? Your ideas are
appreciated.

~Jeff
 
The first thing I'd check is macro security and whether normal macros run.

Also note: The newsgroup interface you are using apparently does not quote
earlier messages in the thread, making your latest message so short on
detail that you risk not getting the answer you're looking for. Please take
the time to quote the original message.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I checked your website and used the SelfCert tool to make
myself a certificate and have solved the problem.

Thank you.

~Jeff
 
Back
Top