<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Automatically triage emails by sender name</title>
	<atom:link href="http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/</link>
	<description>Automation and VBA code for Microsoft® Excel and Outlook</description>
	<lastBuildDate>Fri, 03 Sep 2010 11:28:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Jeremy</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2631</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Tue, 11 May 2010 14:20:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2631</guid>
		<description>I fixed the Run-Time error &#039;459&#039; not the 13.  I couldn&#039;t get the code to work despite making the changes.  I don&#039;t need it anymore anyway.  Sorry I couldn&#039;t help. It seemed to work if the folder you are putting the mail in is a subfolder within the &quot;inbox&quot;.</description>
		<content:encoded><![CDATA[<p>I fixed the Run-Time error '459' not the 13.  I couldn't get the code to work despite making the changes.  I don't need it anymore anyway.  Sorry I couldn't help. It seemed to work if the folder you are putting the mail in is a subfolder within the "inbox".</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ann</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2627</link>
		<dc:creator>Ann</dc:creator>
		<pubDate>Mon, 10 May 2010 16:25:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2627</guid>
		<description>Jeremy- you said that you fixed the Runtime error- I am getting an error 13 on this line:
Set msg = objExplorer.Selection(1)

what did you change??</description>
		<content:encoded><![CDATA[<p>Jeremy- you said that you fixed the Runtime error- I am getting an error 13 on this line:<br />
Set msg = objExplorer.Selection(1)</p>
<p>what did you change??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Krtek</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2562</link>
		<dc:creator>Adam Krtek</dc:creator>
		<pubDate>Mon, 12 Apr 2010 15:08:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2562</guid>
		<description>Hi Jeremy-

Thank you so much for the code.  I finally had some time to give it a run thru, and it appears to work initially, though I get an error 13 - type mismatch.  Any thoughts?


Here is what I have (I added the &#039;------------- for better visibility)
Function CheckForFolder(strFolder As String) As Boolean
&#039; looks for subfolder of specified folder, returns TRUE if folder exists.
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olInbox As Outlook.MAPIFolder
Dim FolderToCheck As Outlook.MAPIFolder

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace(&quot;MAPI&quot;)
Set olInbox = olNS.GetDefaultFolder(olFolderInbox)

&#039; try to set an object reference to specified folder
On Error Resume Next
Set FolderToCheck = olInbox.Folders(strFolder)
On Error GoTo 0

If Not FolderToCheck Is Nothing Then
  CheckForFolder = True
End If

ExitProc:
Set FolderToCheck = Nothing
Set olInbox = Nothing
Set olNS = Nothing
Set olApp = Nothing
End Function
&#039;-------------------------------------------------------------------------------------------
 Function CreateSubFolder(strFolder As String) As Outlook.MAPIFolder
&#039; assumes folder doesn&#039;t exist, so only call if calling sub knows that
&#039; the folder doesn&#039;t exist; returns a folder object to calling sub
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olInbox As Outlook.MAPIFolder

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace(&quot;MAPI&quot;)
Set olInbox = olNS.GetDefaultFolder(olFolderInbox)

Set CreateSubFolder = olInbox.Folders.Add(strFolder)

ExitProc:
Set olInbox = Nothing
Set olNS = Nothing
Set olApp = Nothing
End Function
 

&#039;-------------------------------------
 Public Sub MoveIt()
 On Error GoTo ErrorHandler

  Dim fldr As Outlook.MAPIFolder
  Dim msg As Outlook.MailItem
  Dim targetFolder As Outlook.MAPIFolder
  Dim senderName As String

  Set fldr = GetNS(GetOutlookApp).PickFolder

  If fldr Is Nothing Then GoTo ErrorHandler

  For Each msg In fldr.Items

    &#039; move received email to target folder based on sender name
   senderName = msg.senderName

    If CheckForFolder(senderName) = False Then  &#039; Folder doesn&#039;t exist
     Set targetFolder = CreateSubFolder(senderName)
    Else
      Set targetFolder = _
      GetNS(GetOutlookApp).GetDefaultFolder(olFolderInbox).Folders(senderName)
    End If

    msg.Move targetFolder

  Next msg

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number &amp; &quot; - &quot; &amp; Err.Description
  Resume ProgramExit
End Sub
&#039;-------------------------------------------------------------------
Function GetOutlookApp() As Outlook.Application
&#039; returns reference to native Outlook.Application object
 Set GetOutlookApp = Outlook.Application
End Function
&#039;-------------------------------------------------------------------------
Function GetNS(ByRef app As Outlook.Application) _
         As Outlook.NameSpace
&#039; returns a Namespace Object to access MAPIFolder objects
 Set GetNS = app.GetNamespace(&quot;MAPI&quot;)
End Function

Thanks
Adam</description>
		<content:encoded><![CDATA[<p>Hi Jeremy-</p>
<p>Thank you so much for the code.  I finally had some time to give it a run thru, and it appears to work initially, though I get an error 13 &#8211; type mismatch.  Any thoughts?</p>
<p>Here is what I have (I added the '&#8212;&#8212;&#8212;&#8212;- for better visibility)<br />
Function CheckForFolder(strFolder As String) As Boolean<br />
' looks for subfolder of specified folder, returns TRUE if folder exists.<br />
Dim olApp As Outlook.Application<br />
Dim olNS As Outlook.NameSpace<br />
Dim olInbox As Outlook.MAPIFolder<br />
Dim FolderToCheck As Outlook.MAPIFolder</p>
<p>Set olApp = Outlook.Application<br />
Set olNS = olApp.GetNamespace("MAPI")<br />
Set olInbox = olNS.GetDefaultFolder(olFolderInbox)</p>
<p>' try to set an object reference to specified folder<br />
On Error Resume Next<br />
Set FolderToCheck = olInbox.Folders(strFolder)<br />
On Error GoTo 0</p>
<p>If Not FolderToCheck Is Nothing Then<br />
  CheckForFolder = True<br />
End If</p>
<p>ExitProc:<br />
Set FolderToCheck = Nothing<br />
Set olInbox = Nothing<br />
Set olNS = Nothing<br />
Set olApp = Nothing<br />
End Function<br />
'&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
 Function CreateSubFolder(strFolder As String) As Outlook.MAPIFolder<br />
' assumes folder doesn't exist, so only call if calling sub knows that<br />
' the folder doesn't exist; returns a folder object to calling sub<br />
Dim olApp As Outlook.Application<br />
Dim olNS As Outlook.NameSpace<br />
Dim olInbox As Outlook.MAPIFolder</p>
<p>Set olApp = Outlook.Application<br />
Set olNS = olApp.GetNamespace("MAPI")<br />
Set olInbox = olNS.GetDefaultFolder(olFolderInbox)</p>
<p>Set CreateSubFolder = olInbox.Folders.Add(strFolder)</p>
<p>ExitProc:<br />
Set olInbox = Nothing<br />
Set olNS = Nothing<br />
Set olApp = Nothing<br />
End Function</p>
<p>'&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
 Public Sub MoveIt()<br />
 On Error GoTo ErrorHandler</p>
<p>  Dim fldr As Outlook.MAPIFolder<br />
  Dim msg As Outlook.MailItem<br />
  Dim targetFolder As Outlook.MAPIFolder<br />
  Dim senderName As String</p>
<p>  Set fldr = GetNS(GetOutlookApp).PickFolder</p>
<p>  If fldr Is Nothing Then GoTo ErrorHandler</p>
<p>  For Each msg In fldr.Items</p>
<p>    ' move received email to target folder based on sender name<br />
   senderName = msg.senderName</p>
<p>    If CheckForFolder(senderName) = False Then  ' Folder doesn't exist<br />
     Set targetFolder = CreateSubFolder(senderName)<br />
    Else<br />
      Set targetFolder = _<br />
      GetNS(GetOutlookApp).GetDefaultFolder(olFolderInbox).Folders(senderName)<br />
    End If</p>
<p>    msg.Move targetFolder</p>
<p>  Next msg</p>
<p>ProgramExit:<br />
  Exit Sub<br />
ErrorHandler:<br />
  MsgBox Err.Number &amp; " &#8211; " &amp; Err.Description<br />
  Resume ProgramExit<br />
End Sub<br />
'&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Function GetOutlookApp() As Outlook.Application<br />
' returns reference to native Outlook.Application object<br />
 Set GetOutlookApp = Outlook.Application<br />
End Function<br />
'&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Function GetNS(ByRef app As Outlook.Application) _<br />
         As Outlook.NameSpace<br />
' returns a Namespace Object to access MAPIFolder objects<br />
 Set GetNS = app.GetNamespace("MAPI")<br />
End Function</p>
<p>Thanks<br />
Adam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2555</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Fri, 09 Apr 2010 23:56:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2555</guid>
		<description>That&#039;s right. Try

Set objFolder = objNS.Folders(&quot;Old Mail&quot;).Folders(&quot;Personal&quot;)</description>
		<content:encoded><![CDATA[<p>That's right. Try</p>
<p>Set objFolder = objNS.Folders("Old Mail").Folders("Personal")</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2550</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Fri, 09 Apr 2010 15:12:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2550</guid>
		<description>I wish i could edit my post.  Ok, I figured out the problem, which led me to another.

Set myFolder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders(&quot;personal&quot;)

This program works fine if i have a folder inside my Inbox called personal.  However, i have it inside a folder stored and backup up on our network called Old Mail its a .pst file.  So, i have a &quot;Personal&quot; folder inside of &quot;Old Mail&quot;. So I edited the line to this:

Set myFolder = Outlook.Session.GetDefaultFolder(&quot;Old Mail&quot;).Folders(&quot;Personal&quot;)

Now i have a run-time error 13 i think it was. The original code i posted to find this folder worked.
Set objFolder = objNS.Folders(&quot;Old Mail -Beeson&quot;).Folders(&quot;Personal&quot;)

I have since renamed the folder to simply &quot;Old Mail&quot;
Can it not find the folder because of the &quot;.GetDefaultFolder&quot;?</description>
		<content:encoded><![CDATA[<p>I wish i could edit my post.  Ok, I figured out the problem, which led me to another.</p>
<p>Set myFolder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders("personal")</p>
<p>This program works fine if i have a folder inside my Inbox called personal.  However, i have it inside a folder stored and backup up on our network called Old Mail its a .pst file.  So, i have a "Personal" folder inside of "Old Mail". So I edited the line to this:</p>
<p>Set myFolder = Outlook.Session.GetDefaultFolder("Old Mail").Folders("Personal")</p>
<p>Now i have a run-time error 13 i think it was. The original code i posted to find this folder worked.<br />
Set objFolder = objNS.Folders("Old Mail -Beeson").Folders("Personal")</p>
<p>I have since renamed the folder to simply "Old Mail"<br />
Can it not find the folder because of the ".GetDefaultFolder"?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2549</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Fri, 09 Apr 2010 14:28:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2549</guid>
		<description>Thank you! One small problem with the code, I get this error:

Run-Time error &#039;459&#039;:
Object or class does not support the set of events

It then points to this line of code -&gt;  Set msg = objExplorer.Selection(1)

I&#039;m not sure whats its looking for at Run-time that&#039;s not available. That&#039;s a part of the code I&#039;m not familiar with.  I did change the name of the person in the code.</description>
		<content:encoded><![CDATA[<p>Thank you! One small problem with the code, I get this error:</p>
<p>Run-Time error '459':<br />
Object or class does not support the set of events</p>
<p>It then points to this line of code -&gt;  Set msg = objExplorer.Selection(1)</p>
<p>I'm not sure whats its looking for at Run-time that's not available. That's a part of the code I'm not familiar with.  I did change the name of the person in the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2545</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Thu, 08 Apr 2010 21:19:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2545</guid>
		<description>Jeremy --

This code will automatically move emails from a given sender to a subfolder called &quot;personal&quot; whenever an email from that sender is read. Edit as needed. Note that opening emails will also mark them as read.

[cc lang=&#039;vb&#039;]Private WithEvents objExplorer As Outlook.Explorer
Private WithEvents msg As Outlook.MailItem

Private Sub Application_Startup()
  Set objExplorer = Application.ActiveExplorer
End Sub

Private Sub msg_PropertyChange(ByVal Name As String)
  Dim myFolder As Outlook.MAPIFolder

If msg.UnRead = False Then
  If msg.senderName = &quot;the name you are looking for&quot; Then
    Set myFolder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders(&quot;personal&quot;)
    msg.Move myFolder
  End If
End If
End Sub

Private Sub objExplorer_SelectionChange()
  If objExplorer.CurrentFolder.DefaultItemType = olMailItem Then
    If objExplorer.Selection.Count &gt; 0 Then
      Set msg = objExplorer.Selection(1)
    End If
  End If
End Sub[/cc]</description>
		<content:encoded><![CDATA[<p>Jeremy &#8211;</p>
<p>This code will automatically move emails from a given sender to a subfolder called "personal" whenever an email from that sender is read. Edit as needed. Note that opening emails will also mark them as read.</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Private</span> <span style="color: #000080;">WithEvents</span> objExplorer <span style="color: #000080;">As</span> Outlook.Explorer<br />
<span style="color: #000080;">Private</span> <span style="color: #000080;">WithEvents</span> msg <span style="color: #000080;">As</span> Outlook.MailItem<br />
<br />
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> Application_Startup()<br />
&nbsp; <span style="color: #000080;">Set</span> objExplorer = Application.ActiveExplorer<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span><br />
<br />
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> msg_PropertyChange(<span style="color: #000080;">ByVal</span> Name <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>)<br />
&nbsp; <span style="color: #000080;">Dim</span> myFolder <span style="color: #000080;">As</span> Outlook.MAPIFolder<br />
<br />
<span style="color: #000080;">If</span> msg.UnRead = <span style="color: #000080;">False</span> <span style="color: #000080;">Then</span><br />
&nbsp; <span style="color: #000080;">If</span> msg.senderName = <span style="color: #800000;">&quot;the name you are looking for&quot;</span> <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; <span style="color: #000080;">Set</span> myFolder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders(<span style="color: #800000;">&quot;personal&quot;</span>)<br />
&nbsp; &nbsp; msg.Move myFolder<br />
&nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span><br />
<br />
<span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> objExplorer_SelectionChange()<br />
&nbsp; <span style="color: #000080;">If</span> objExplorer.CurrentFolder.DefaultItemType = olMailItem <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; <span style="color: #000080;">If</span> objExplorer.Selection.Count &gt; 0 <span style="color: #000080;">Then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000080;">Set</span> msg = objExplorer.Selection(1)<br />
&nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
&nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2541</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Wed, 07 Apr 2010 16:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2541</guid>
		<description>So I&#039;ve been looking for a macro as well that will run as soon as an email is marked as read.  I&#039;m trying to catch emails from a specific sender.  So, say the person emails me, i click the email to read it, it shows in the reading pane, and i click away - therefore marking it as read, it would then be moved to a folder called &quot;personal&quot;.  I currently have a manual macro that i have to click to run, but I can&#039;t seem to grab the sender&#039;s name or email address.  We are on an exchange server with outlook 2007. Here&#039;s what i have... *I edited this line &#039;If senderName = &quot;Person&#039;s name&quot; Then&#039; for anonymity* Person&#039;s name is either address or the name associated with the contact record. Such as John Doe johndoe@example.com

[cc lang=&#039;vb&#039;]Sub MoveToArchive()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Dim senderName As String


Set objNS = Application.GetNamespace(&quot;MAPI&quot;)
Set objFolder = objNS.Folders(&quot;Old Mail -Beeson&quot;).Folders(&quot;Personal&quot;)
&#039;Assume this is a mail folder


If objFolder Is Nothing Then
MsgBox &quot;This folder doesn&#039;t exist!&quot;, vbOKOnly + vbExclamation, &quot;INVALID FOLDER&quot;
End If


If Application.ActiveExplorer.Selection.Count = 0 Then
&#039;Require that this procedure be called only when a message is selected
Exit Sub
End If

senderName = msg.senderName
If senderName = &quot;Person&#039;s name&quot; Then


For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.UnRead = False
objItem.Move objFolder
End If
End If
Next

Else
&#039;for Sender name
End If

Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
End Sub[/cc]</description>
		<content:encoded><![CDATA[<p>So I've been looking for a macro as well that will run as soon as an email is marked as read.  I'm trying to catch emails from a specific sender.  So, say the person emails me, i click the email to read it, it shows in the reading pane, and i click away &#8211; therefore marking it as read, it would then be moved to a folder called "personal".  I currently have a manual macro that i have to click to run, but I can't seem to grab the sender's name or email address.  We are on an exchange server with outlook 2007. Here's what i have&#8230; *I edited this line 'If senderName = "Person's name" Then' for anonymity* Person's name is either address or the name associated with the contact record. Such as John Doe <a href="mailto:johndoe@example.com">johndoe@example.com</a></p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000080;">Sub</span> MoveToArchive()<br />
<span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span><br />
<span style="color: #000080;">Dim</span> objFolder <span style="color: #000080;">As</span> Outlook.MAPIFolder<br />
<span style="color: #000080;">Dim</span> objNS <span style="color: #000080;">As</span> Outlook.NameSpace, objItem <span style="color: #000080;">As</span> Outlook.MailItem<br />
<span style="color: #000080;">Dim</span> senderName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span><br />
<br />
<br />
<span style="color: #000080;">Set</span> objNS = Application.GetNamespace(<span style="color: #800000;">&quot;MAPI&quot;</span>)<br />
<span style="color: #000080;">Set</span> objFolder = objNS.Folders(<span style="color: #800000;">&quot;Old Mail -Beeson&quot;</span>).Folders(<span style="color: #800000;">&quot;Personal&quot;</span>)<br />
<span style="color: #008000;">'Assume this is a mail folder<br />
</span><br />
<br />
<span style="color: #000080;">If</span> objFolder <span style="color: #000080;">Is</span> <span style="color: #000080;">Nothing</span> <span style="color: #000080;">Then</span><br />
MsgBox <span style="color: #800000;">&quot;This folder doesn't exist!&quot;</span>, vbOKOnly + vbExclamation, <span style="color: #800000;">&quot;INVALID FOLDER&quot;</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<br />
<br />
<span style="color: #000080;">If</span> Application.ActiveExplorer.Selection.Count = 0 <span style="color: #000080;">Then</span><br />
<span style="color: #008000;">'Require that this procedure be called only when a message is selected<br />
</span><span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<br />
senderName = msg.senderName<br />
<span style="color: #000080;">If</span> senderName = <span style="color: #800000;">&quot;Person's name&quot;</span> <span style="color: #000080;">Then</span><br />
<br />
<br />
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objItem <span style="color: #000080;">In</span> Application.ActiveExplorer.Selection<br />
<span style="color: #000080;">If</span> objFolder.DefaultItemType = olMailItem <span style="color: #000080;">Then</span><br />
<span style="color: #000080;">If</span> objItem.Class = olMail <span style="color: #000080;">Then</span><br />
objItem.UnRead = <span style="color: #000080;">False</span><br />
objItem.Move objFolder<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<span style="color: #000080;">Next</span><br />
<br />
<span style="color: #000080;">Else</span><br />
<span style="color: #008000;">'for Sender name<br />
</span><span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<br />
<span style="color: #000080;">Set</span> objItem = <span style="color: #000080;">Nothing</span><br />
<span style="color: #000080;">Set</span> objFolder = <span style="color: #000080;">Nothing</span><br />
<span style="color: #000080;">Set</span> objNS = <span style="color: #000080;">Nothing</span><br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: JP</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2485</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Sat, 27 Mar 2010 13:50:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2485</guid>
		<description>Adam --

Try this. It lets you pick a folder and then loops through it, moving the items based on sender name into their own folders one level below the default Inbox. If the folder doesn&#039;t exist, it is created. You&#039;ll also need to grab the CheckForFolder and CreateSubFolder procedures, found at &lt;a href=&quot;http://www.codeforexcelandoutlook.com/blog/2008/12/look-for-and-create-folders-programmatically-in-outlook/&quot; rel=&quot;nofollow&quot;&gt;Look for and create folders programmatically.&lt;/a&gt;

[cc lang=&#039;vb&#039;]
  On Error GoTo ErrorHandler

  Dim fldr As Outlook.MAPIFolder
  Dim msg As Outlook.MailItem
  Dim targetFolder As Outlook.MAPIFolder
  Dim senderName As String

  Set fldr = GetNS(GetOutlookApp).PickFolder

  If fldr Is Nothing Then GoTo ErrorHandler

  For Each msg In fldr.Items

    &#039; move received email to target folder based on sender name
    senderName = msg.senderName

    If CheckForFolder(senderName) = False Then  &#039; Folder doesn&#039;t exist
      Set targetFolder = CreateSubFolder(senderName)
    Else
      Set targetFolder = _
      GetNS(GetOutlookApp).GetDefaultFolder(olFolderInbox).Folders(senderName)
    End If

    msg.Move targetFolder

  Next msg

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number &amp; &quot; - &quot; &amp; Err.Description
  Resume ProgramExit
End Sub

Function GetOutlookApp() As Outlook.Application
&#039; returns reference to native Outlook.Application object
  Set GetOutlookApp = Outlook.Application
End Function

Function GetNS(ByRef app As Outlook.Application) _
         As Outlook.NameSpace
&#039; returns a Namespace Object to access MAPIFolder objects
  Set GetNS = app.GetNamespace(&quot;MAPI&quot;)
End Function[/cc]</description>
		<content:encoded><![CDATA[<p>Adam &#8211;</p>
<p>Try this. It lets you pick a folder and then loops through it, moving the items based on sender name into their own folders one level below the default Inbox. If the folder doesn't exist, it is created. You'll also need to grab the CheckForFolder and CreateSubFolder procedures, found at <a href="http://www.codeforexcelandoutlook.com/blog/2008/12/look-for-and-create-folders-programmatically-in-outlook/" rel="nofollow">Look for and create folders programmatically.</a></p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:630px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">GoTo</span> ErrorHandler<br />
<br />
&nbsp; <span style="color: #000080;">Dim</span> fldr <span style="color: #000080;">As</span> Outlook.MAPIFolder<br />
&nbsp; <span style="color: #000080;">Dim</span> msg <span style="color: #000080;">As</span> Outlook.MailItem<br />
&nbsp; <span style="color: #000080;">Dim</span> targetFolder <span style="color: #000080;">As</span> Outlook.MAPIFolder<br />
&nbsp; <span style="color: #000080;">Dim</span> senderName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span><br />
<br />
&nbsp; <span style="color: #000080;">Set</span> fldr = GetNS(GetOutlookApp).PickFolder<br />
<br />
&nbsp; <span style="color: #000080;">If</span> fldr <span style="color: #000080;">Is</span> <span style="color: #000080;">Nothing</span> <span style="color: #000080;">Then</span> <span style="color: #000080;">GoTo</span> ErrorHandler<br />
<br />
&nbsp; <span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> msg <span style="color: #000080;">In</span> fldr.Items<br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">' move received email to target folder based on sender name<br />
</span> &nbsp; &nbsp;senderName = msg.senderName<br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">If</span> CheckForFolder(senderName) = <span style="color: #000080;">False</span> <span style="color: #000080;">Then</span> &nbsp;<span style="color: #008000;">' Folder doesn't exist<br />
</span> &nbsp; &nbsp; &nbsp;<span style="color: #000080;">Set</span> targetFolder = CreateSubFolder(senderName)<br />
&nbsp; &nbsp; <span style="color: #000080;">Else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000080;">Set</span> targetFolder = _<br />
&nbsp; &nbsp; &nbsp; GetNS(GetOutlookApp).GetDefaultFolder(olFolderInbox).Folders(senderName)<br />
&nbsp; &nbsp; <span style="color: #000080;">End</span> <span style="color: #000080;">If</span><br />
<br />
&nbsp; &nbsp; msg.Move targetFolder<br />
<br />
&nbsp; <span style="color: #000080;">Next</span> msg<br />
<br />
ProgramExit:<br />
&nbsp; <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span><br />
ErrorHandler:<br />
&nbsp; MsgBox Err.Number &amp; <span style="color: #800000;">&quot; - &quot;</span> &amp; Err.Description<br />
&nbsp; <span style="color: #000080;">Resume</span> ProgramExit<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span><br />
<br />
<span style="color: #000080;">Function</span> GetOutlookApp() <span style="color: #000080;">As</span> Outlook.Application<br />
<span style="color: #008000;">' returns reference to native Outlook.Application object<br />
</span> &nbsp;<span style="color: #000080;">Set</span> GetOutlookApp = Outlook.Application<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span><br />
<br />
<span style="color: #000080;">Function</span> GetNS(<span style="color: #000080;">ByRef</span> app <span style="color: #000080;">As</span> Outlook.Application) _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000080;">As</span> Outlook.NameSpace<br />
<span style="color: #008000;">' returns a Namespace Object to access MAPIFolder objects<br />
</span> &nbsp;<span style="color: #000080;">Set</span> GetNS = app.GetNamespace(<span style="color: #800000;">&quot;MAPI&quot;</span>)<br />
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Krtek</title>
		<link>http://www.codeforexcelandoutlook.com/blog/2009/09/automatically-triage-emails-by-sender-name/#comment-2467</link>
		<dc:creator>Adam Krtek</dc:creator>
		<pubDate>Wed, 24 Mar 2010 14:01:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codeforexcelandoutlook.com/blog/?p=720#comment-2467</guid>
		<description>Thanks for your code.  I am new to VBA for the last month and a half but am picking it up nicely.  I am just starting to make my foray into Outlook and could use some help modifying your code to my needs.

Instead of the code running anytime a new item is added to the reference folder, I would like to tell it when to run.  I currently am using rules in 2007 to move emails from members of a select department in our company into their own personal folders.  I have so many of these now, that I do not see them unless I scroll down thru my subfolders.  A more ideal situation is to have them all come into one folder labeled with the department name.  On Friday, I would like to run the macro to move any of these messages that are read to the folder of that sender.  This way I can manage my unread and todo items from the sender before moving the items.

Any thoughts?

Thanks
Adam</description>
		<content:encoded><![CDATA[<p>Thanks for your code.  I am new to VBA for the last month and a half but am picking it up nicely.  I am just starting to make my foray into Outlook and could use some help modifying your code to my needs.</p>
<p>Instead of the code running anytime a new item is added to the reference folder, I would like to tell it when to run.  I currently am using rules in 2007 to move emails from members of a select department in our company into their own personal folders.  I have so many of these now, that I do not see them unless I scroll down thru my subfolders.  A more ideal situation is to have them all come into one folder labeled with the department name.  On Friday, I would like to run the macro to move any of these messages that are read to the folder of that sender.  This way I can manage my unread and todo items from the sender before moving the items.</p>
<p>Any thoughts?</p>
<p>Thanks<br />
Adam</p>
]]></content:encoded>
	</item>
</channel>
</rss>
