My goal is no make Outlook delete all mail from a specified address keeping maximum 3 latest (it really helps with some daily subscriptions like coupons, etc.).

I have lots of rules sorting mail into different folders and marking them with a special category (let's call it "Amount: 3"). I also have the last rule in the list that runs my VBA script: it counts mail from the same sender in a folder (having this "Amount: 3" category) and deletes old leaving no more than the amount requested.
The whole thing works fine when Outlook is running and receives new mail. But when I start Outlook for the first time and there's new mail on the server - it randomly tells that the script rule failed to execute and turns it off...
My script does logging so I'm quite sure it's not an incorrect script issue. Moreover it seems like when I turn on debug logging in Outlook - the problem disappears. And there's nothing suspicious in the system journal too...

So the question is how can I find out what's wrong with it?? If negative - is there a way to acheive what I want in Outlook 2013?
And yes I know that MS suggests not using VBA rule together with other kinds of rules no matter the order and so on, but still can't believe they've made it so unpredictable...

ps: the same solution worked more or less stable at Outlook 2007 back in the days...

  • Not sure what the problem is, sounds rather like some kind of timing edge case. However, I'd be tempted to do it in two stages. Firstly mark anything that could be deleted with a Category. Then delete all mails with that category - that could happen in a separate process if needed. You could also then delete mail manually as well. Apr 1 '15 at 23:20
  • My belief is that Outlook starts with several threads doing initialization, etc. And when one of them starts receiving new mail, another one doing VBA initialization, is not ready yet... As for your advise - how can I do the second part (delete all mail with that category) automatically but without rules engine/VBA (since it doesn't work according to my question :) )? Apr 2 '15 at 15:39
  • Easiest way is to create a custom search folder against the category you use. It will find all of the emails in that category. You can then delete them with ctrl-a, del. Apr 2 '15 at 15:41
  • That still requires manual actions. Not that much, but still :) Apr 2 '15 at 15:43
  • Yes, that is true. However, you could run some VBA on startup & shutdown that deletes everything in that virtual folder. That will work because you are not dependent on any mail transport events. Apr 3 '15 at 8:01

If instead of trying to do everything in one go, you were to mark anything you want deleted with a Category. You could then create a virtual search folder for that category. This has the advantage of working across all actual folders.

You could then write some simple VBA that is executed at startup and shutdown of Outlook that deletes the contents of that virtual search folder.

Then you are not dependent on the mail transport events firing in the right order.

  • Well, technically this one should not crash (at least it doesn't use VBA rule). But it doesn't actually solve the problem: the idea was not to decrease the mailbox size, but to seamlessly sort out meaningless subscription mails. Apr 6 '15 at 23:00
  • I've made the following WA: my VBA rule is now turned on by an Outlook Startup event (and executed for all unread mail items at the same time) and turned off by an Outlook Quit event. Will wait and see if my assumption above about inability to call VBA from a rule is correct ) Apr 6 '15 at 23:04
  • Reverted all this Startup/Exit events handling ('cause it didn't work either) - did fallback to the original scheme with rule-driven VBA, but moved all the VBA code from a separate module into ThisOutlookSession object - and it seems to work now! Will watch it for some more time though... Apr 14 '15 at 21:53

Man! It looks like I've finally fixed it (facepalm) So the way it works all the times is:

  • Same rule-based VBA sub doing major stuff
  • Application_Startup/Application_Quit event handlers to turn on/off corresponding rule to avoid random errors on Outlook start (see my comments to question/answers here)
  • Autolaunch shortcut copypasted from Microsoft Office 2013 folder of Start -> All Programs (it was shortcut to OUTLOOK.EXE originally and it appears that it doesn't fire event handlers at all when you launch Outlook that way O_o)
  • #$%^$! It doesn't work either after some time. Dunno what to do anymore. Just wanna forget that horrible Outlook ( Aug 19 '15 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.