File all Emails by Sender in the Inbox and Move to Folder according to Pre-set Rule

O

ollie

Hopefully Sue can help me or someone else here.

I need to right a macro in order to make filing my Inbox emails simpler
in outlook 2003.

Simply, I want to right Click an Email that's in my Inbox and then have
ALL of the emails from the sender in my Inbox "MOVED" to a
pre-determined sub folder (from a rule).

So I can and have created rules to move emails from specific Senders to
the folder as they arrive but basically I want to read the emails
first that arrive in my Inbox and then "Move Them" to a pre-specified
folder that I have determined using the Rule Wizard.

So I first create the rule but turn off run rules automatically for the
ones which say emails from Sender X move to Folder Y.

Now I need to create the Right-Click Menu Macro to 'File All Senders
Emails'.

Could someone show me the VBA Code necessary to do this Please?

Logic is this.

With
Current Selected Mail Item
Search All Mail Items with Senders Name in Current Folder
Where Rule Contains Name of Sender Run this Rule for All Mail Items
in Current Folder

Obviously it would be better if Outlook could have Subfolders
associated to Contacts in the Addressbook that way instead of having to
run the rule wizard, for certain filing actions, you could call the
associated Folder Property in VBA or .NET.

Many Thanks

Ollie
 
K

Ken Slovak - [MVP - Outlook]

Using the context menu in an Explorer is a hack in versions earlier than
Outlook 2007 and does not tell you which item was right-clicked. If it's the
ActiveExplorer.Selection(1) item and only 1 item is selected it might work,
otherwise forget it. For code to work with the context menu search for
"context menu" at www.outlookcode.com, but it's not a real good way.

Why not just run the rule manually when you want to? It's a couple of
additional clicks but it will work.
 
O

ollie

Thanks Ken,

I have used an example and modified it to get the Context Menu to Work.
So I select a Mail Item and then right click and my macro is in the
Menu.

But I cannot make the code then invoke a rule.

Its too many clicks to make an individual rule run in 2003. You can
only run all or nothing, or go through the wizard for each rule until
you can run it independently! Thats my problem.

If I could invoke a rule based on the SenderName of the Mail Item I
would be away

Do you know How I could do this?

Here is My Context Menu Code That Works:-
_________________

'' This is the right click code (Context Menu Command)
''ok

Dim WithEvents m_objMail As Outlook.MailItem
Dim WithEvents m_objExpl As Outlook.Explorer

Private m_blnIsMailFolder As Boolean
'ok
Private Sub Application_Startup()
Set m_objExpl = Application.ActiveExplorer
End Sub
'ok
Private Sub m_objExpl_Close()
If Application.Explorers.Count > 0 Then
Set m_objExpl = Application.ActiveExplorer
Else
Set m_objExpl = Nothing
Set m_objMail = Nothing
End If
End Sub

Private Sub m_objExpl_FolderSwitch()
Dim objFolder As Outlook.MAPIFolder

'Set myMailItems =
myNameSpace.GetDefaultFolder(olFolderInbox).Items

Set objFolder = m_objExpl.CurrentFolder
'Set objFolder = Nothing
End Sub

Private Sub m_objExpl_SelectionChange()
Dim objItem As Object
Dim objAction As Outlook.Action
If m_objExpl.Selection.Count > 0 Then
Set objItem = m_objExpl.Selection(1)
If objItem.Class = olMail Then
Set m_objMail = objItem
Set objAction = m_objMail.Actions("My Reply")
If objAction Is Nothing Then
Set objAction = m_objMail.Actions.Add
With objAction
.Enabled = True
.Name = "My Reply"
.ShowOn = olMenu
End With
m_objMail.Save
End If
End If
End If
Set objItem = Nothing
Set objAction = Nothing
End Sub



Private Sub m_objMail_CustomAction(ByVal Action As Object, _
ByVal Response As Object, _
Cancel As Boolean)
MsgBox Action.Name, , "m_objMail_CustomAction"


Cancel = True
End Sub
 
K

Ken Slovak - [MVP - Outlook]

You cannot call a rule from code unless you are using Outlook 2007 and
access the new Rules collection. You would have to replicate the entire rule
using your macro code.
 

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