views:

564

answers:

1

I'm trying to get Outlook to save the attachment in a daily email to a folder where I can have a file system watcher ready to parse and analyze the attachment (it's the report of a data integrity checker). I've set up a Rule that is supposed to run a VBA script, but it just doesn't run as far as I can tell. I've verified in VB6 that the code will in fact save some text to a file, so if Outlook actually runs the VBA script it should be able to do the same. But it doesn't! Can anyone see what the heck I'm doing wrong?

Dim WithEvents objInbox As Outlook.Items

Private Sub Application_Startup()
   Set objInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Sub SnagAttachment(theItem As MailItem)
    On Error Resume Next
    Dim fnum As Integer
    fnum = FreeFile()
    Open "c:\temp\success.txt" For Output As #fnum
    Print #fnum, "Ran SnagAttachment Successfully"
    Close #fnum
End Sub

Note that when I use the Rules wizard, and choose "run a script" the Sub SnagAttachment is listed as a script that can be selected.

A: 

Try isolating the exact problem:

  1. Check macro security settings. At maximum, it must be set no higher than "Warnings for all macros".
  2. Try creating a new module with a single test sub:
    Sub Test(Item as Outlook.MailItem)
    MsgBox "test"
    End Sub
    
    Then set up a new rule to handle _all_ incoming messages running this sub as the only action, and temporarily disable all other rules. Then send a message to yourself. If you get no popup box as a result, this may be an indication of a bad Outlook install. Try reinstalling it, or calling MS up directly for support.
  3. If the previous test was successful, try working with the `Scripting.FileSystemObject` object instead of `Freefile()` to create and populate files. This is just to test if there's some odd bug you're encountering here. Worth a shot, right?
  4. Make sure your rule conditions are set correctly. There could be a glitch or misspelling in a condition which just drops all messages you want this script to run on.
bob-the-destroyer