Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA to move outbound email and mark as read?

107 views
Skip to first unread message

ajke...@gmail.com

unread,
Apr 19, 2006, 9:57:09 AM4/19/06
to
Using Outlook 2003, how would I create a custom rule to move outbound
email to a specific folder and mark as read? Similar questions have
popped up several times before, e.g.:

http://groups.google.com/group/microsoft.public.outlook.general/browse_thread/thread/6b43d8ad1f60fe4b/39c9278193fa52c3
http://groups.google.com/group/microsoft.public.outlook.program_vba/browse_thread/thread/48ef57063851dc47/8eb8d0891b74ea23

But I haven't found any clear, simple answers. It is odd that Outlook
doesn't have a "mark as read" action to begin with, but since that
seems to be the case, can someone point me to a step-by-step
explanation for how to create a custom action in VBA that marks the
message as read and then associate that action with a rule in the Rules
Wizard?

The only other option seems to be going through all of the folders to
which sent mail has automatically been moved and doing 'mark all as
read' every day or every few hours, which would be quite inefficient.

Eric Legault [MVP - Outlook]

unread,
Apr 19, 2006, 3:45:01 PM4/19/06
to
How are your Sent Items being marked as unread anyway?

You can use code as outlined in my blog:

Macro Magic - Changing the location of the save sent message folder:
http://blogs.officezealot.com/legault/archive/2004/05/11/214.aspx

You can also fire a macro with a rule:

How to create a script for the Rules Wizard in Outlook:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q306108

To change the read/unread state of a message, use the Unread property.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/

ajke...@gmail.com

unread,
Apr 19, 2006, 9:16:11 PM4/19/06
to
> How are your Sent Items being marked as unread anyway?

Interestingly, every time this issue comes up -- I found about 6 or 7
threads with similar questions -- someone is always surprised that Sent
Items are being marked as unread. I don't understand why this is
surprising. If you go into the Rules Wizard and create a new Rule to
apply to outgoing messages that moves them to a different folder based
on, e.g., a string in the recipient, the message in that different
folder will be marked unread. There will also be duplicate messages in
your "sent items" folder (thus "move" is really a misnomer--it is, in
fact, copying the message). The only way I could figure out to prevent
that from happening was to disable the option to save messages to "sent
items;" have the rules for filtering outbound messages to certain
folders stop processing further rules after the match; and then have a
last "catch all" rule that moves all messages to "sent items."

I will check out your blog, though, thanks for the tip.

ajke...@gmail.com

unread,
Apr 19, 2006, 9:33:04 PM4/19/06
to
On further inspection, it looks like your blog is providing a different
solution: the ability to decide the sent mail folder at the time you
send the message. What I'm looking for is a way to have messages
automatically recognized (by a rule) as to which "sent mail" folder
they belong to.

What I'm stuck on is getting a script to appear as a "custom action" in
the Rules Wizard. I checked out that knowledge base article, but no
matter what I do in the VBA window (even saving and restarting
outlook), my new subroutines do not appear as custom actions. The
script I'm attempting to use as a custom action is very simple:

Sub MarkRead_CustomAction(Item As Outlook.MailItem)
Item.UnRead = False
Item.Save
End Sub

Any idea why it doesn't show up as a custom action?

Eric Legault [MVP - Outlook]

unread,
Apr 19, 2006, 11:41:02 PM4/19/06
to
I pasted your procedure into the ThisOutlookSession module, saved the VBA
project and compiled it - it was then visible in the list for the "Run a
script" rule. Heck, saving and compiling doesn't even matter with a second
dummy procedure that I added which got listed right away as well.

Sorry, I have no idea why this isn't working for you.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/

ajke...@gmail.com

unread,
Apr 20, 2006, 9:02:37 AM4/20/06
to
Does anyone know if there is some type of security setting that might
be blocking my custom procedures in ThisOutlookSession from becoming
available as custom actions?

Eric Legault [MVP - Outlook]

unread,
Apr 20, 2006, 11:27:02 AM4/20/06
to
If you can run other macros, then your security settings are configured
properly.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/

Sue Mosher [MVP-Outlook]

unread,
May 1, 2006, 8:40:32 AM5/1/06
to
VBA procedures are never available as custom actions. Custom actions are separate .dlls built with C++ or Delphi and Extended MAPI. Maybe you're confusing rule custom actions with the CustomAction event on an Outlook item, which is related to the user choosing an action from the Response toolbar? Or with the "run a script" rule action?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

<ajke...@gmail.com> wrote in message news:1145538157....@t31g2000cwb.googlegroups.com...

ajke...@gmail.com

unread,
May 1, 2006, 9:27:56 AM5/1/06
to
I think the problem is that "run a script" is available as an action in
a rule to process incoming mail, but not outgoing mail. Is there some
reason for this difference?

Sue Mosher [MVP-Outlook]

unread,
May 1, 2006, 9:41:27 AM5/1/06
to
Just guessing, it's to avoid confusion and problems related to whether the rule script would run against the item before the send is completed or after.

Code for outgoing items can be handled by the Application_ItemSend event handler or by monitoring the Sent Items folder for new items with the MAPIFolder.Items.ItemAdd event, depending on the application.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

<ajke...@gmail.com> wrote in message news:1146490076.0...@j73g2000cwa.googlegroups.com...

ajke...@gmail.com

unread,
May 2, 2006, 8:50:48 AM5/2/06
to
I don't really understand the confusion--if the script is just another
action like the other outbound rule actions, wouldn't it just run
against the item in the same way all the other actions run against the
item?

In any case, I have tweaked together a solution that seems to work,
which basically involves avoided rules all together. All pattern
matching on the outgoing is done in VBA rather than with a rule. This
seems to be the only practical way to accomplish what I would think
would be a common scenario: moving outbound messages to folders by
pattern matching and marking them as "read" when they are moved to the
outbound folder. (If you just use the rule to move to an outbound
folder, they appear as unread in the outbound folders--and unless you
set up an event handler for each and every outbound folder, there does
not seem to be any systematic rules based way to mark them as read when
they arrive in those folders.)

Sue Mosher [MVP-Outlook]

unread,
May 2, 2006, 10:07:59 AM5/2/06
to
But it's not just another action. The rules wizard does not support a "run a script" action for rules on outgoing messages, most likely for the reasons I described. Items that are in the process of being sent and those that have already been sent are not identical.

But back to your scenario. It sounds like the best solution would be to stick solely with VBA code that monitors the Send Items folder for new items and then moves them based on your criteria and marks the moved copies as read.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

<ajke...@gmail.com> wrote in message news:1146574248.3...@e56g2000cwe.googlegroups.com...

"Sue Mosher [MVP-Outlook]" <sue...@outlookcode.com> wrote in message news:Oig5gXSb...@TK2MSFTNGP03.phx.gbl...


Just guessing, it's to avoid confusion and problems related to whether the rule script would run against the item before the send is completed or after.

Code for outgoing items can be handled by the Application_ItemSend event handler or by monitoring the Sent Items folder for new items with the MAPIFolder.Items.ItemAdd event, depending on the application.

0 new messages