title: Move Mail from Sender to Sender's Folder Name
body: <p>I want to move messages from the sender to the folder I created for the sender.</p>
  
  <p>The SenderName is displayed as "Doe, John (US)" and my folder would be "Doe, John".</p>
  
  <p>What do I need to do to compare the SenderName to a subfolder name that is two levels below <strong><code>"Inbox". I.e. Inbox→Folder1→"Doe, John".</code></strong> </p>
  
  <pre><code>Public Sub MoveToFolder()
  Dim objOutlook As Outlook.Application
  Dim objNameSpace As Outlook.NameSpace
  Dim objDestFolder As Outlook.MAPIFolder
  Dim objSourceFolder As Outlook.Folder
  Dim currentExplorer As Explorer
  Dim Selection As Selection
  Dim obj As Object
  
  Dim objSubfolder As Outlook.Folder
  Dim olsubFolder As Outlook.Folder
  
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Dim olFolder As Outlook.MAPIFolder
  Dim Msg As Outlook.MailItem
  
  Dim objVariant As Variant
  Dim lngMovedItems As Long
  Dim intCount As Integer
  
  Set objOutlook = Application
  Set objNameSpace = objOutlook.GetNamespace("MAPI")
  Set currentExplorer = objOutlook.ActiveExplorer
  Set Selection = currentExplorer.Selection
  Set objSourceFolder = currentExplorer.CurrentFolder
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  
  Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
  Set olFolder = olFolder.Folders("Inbox")
  Set colFolders = objParentFolder.Folders
  
  For Each obj In Selection
      Set objVariant = obj
  
      Dim sfName As Object
      Set sfName = Left(objVariant.senderName, Len(objVariant.senderName) - 5)
  
      If objVariant.Class = olMail Then
  
          On Error Resume Next
          ' Use These lines if the destination folder
          '  is not a subfolder of the current folder
          For Each objSubfolder In colFolders
              For Each olsubFolder In objSubfolder
                  If olsubFolder.Name = sfName Then
                      Set objDestFolder = objSubfolder
                      MsgBox "Ductus Exemplo"
                      'objVariant.Move objDestFolder
                      'count the # of items moved
                      lngMovedItems = lngMovedItems + 1
                       'Display the number of items that were moved.
                      MsgBox "Moved " &amp; lngMovedItems &amp; " messages(s) from  " &amp; _
                      sfName &amp; "to " &amp; objDestFolder
                  Else
                      If objDestFolder Is Nothing Then
                          MsgBox "No Folder Found for " &amp; sfName
                          'Set objDestFolder = objSourceFolder.Folders.Add(sfName)
                          Exit Sub
                      End If
  
              Next
          Next
      Next
  End If
  End Sub
  </code></pre>