title: Switching between accounts then looping through email
body: <p>I am attempting to dump all emails in the junk email folder of a NON-Default outlook account into the inbox so that I can then perform additional logic on the email.
  However I am unable to figure out how to reference the junk box or even the inbox of the non-default account, my code keeps going through my default account even with an account check in place.</p>
  
  <pre><code>Public Sub New_Mail()
  Dim oAccount As Outlook.Account
  Dim objSourceFolder As Outlook.MAPIFolder
  Dim objDestFolder As Outlook.MAPIFolder
  dim lngCount as long
  
  lngcount = 0
  
  For Each oAccount In Application.Session.Accounts  ' cycle through accounts till we find the one we want
      If oAccount = "desired.account@domain.ca" Then
  
          Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderJunk)   ' select junk folder of the account
          Set objDestFolder = objNamespace.GetDefaultFolder(olFolderInbox)    ' select inbox of the account
  
          For lngCount = objSourceFolder.Items.Count To 1 Step -1 ' Go through all items in inbox, if a mail object, move into inbox
              Set objVariant = objSourceFolder.Items.Item(dblCount)
              DoEvents
                  If objVariant.Class = olMail Then
  
                      Set objCurrentEmail = objVariant                ' the inbox item is an email, so change object type to olMail (email object)
  
                      objCurrentEmail.Categories = "red category"
  
                      objCurrentEmail.Move objDestFolder             ' Move the email to the required folder
  
                  End If
          Next
     End If
  Next
  End Sub
  </code></pre>
  
  <hr>
  
  <p>EDIT:
  After Eric's Answer I'd like share my now working code.</p>
  
  <pre><code>Private Sub clearJunk()
  
      Dim objVariant As Variant                   ' Variant object to handle and inbox item
      Dim objCurrentEmail As Outlook.MailItem     ' Temporary email object for logic
      Dim dblCount As Double                      ' Double used to count email items in the inbox
      Dim objStore As Outlook.Store               ' Store Object to cycle through email accounts
      Dim objRoot As Outlook.Folder               ' Folder object to define Inbox of desired account
      Dim folders As Outlook.folders              ' FolderS object to holder folders...lol 
      Dim Folder As Outlook.Folder                ' Temporary Folder object
      Dim foldercount As Integer                  ' integer to count folders in account
      Dim objInboxFolder As Outlook.MAPIFolder    ' MAPI folder object to move emails to or from
      Dim objJunkFolder As Outlook.MAPIFolder     ' MAPI folder object to move emails to or from
      Dim objRandomFolder As Outlook.MAPIFolder   ' MAPI folder object to move emails to or from
  
      '--------------------------------------------------------------------
      ' Cycle through each account in outlook client and find desired account
      For Each objStore In Application.Session.Stores         
          If objStore = "desired.account@domain.ca" Then      ' If we find the account
  
              Set objRoot = objStore.GetRootFolder        ' Store int objRoot Object
  
              On Error Resume Next
  
                  Set folders = objRoot.folders           ' Check if it has folders
                  foldercount = folders.Count
  
                  If foldercount Then                         ' if folders exist
  
                      For Each Folder In folders              ' Go through each folder AND ....
  
                          ' Look for Junk Email folder, Inbox Folder, and some random customer folder.
                          ' Store in individual objects for future referencing
                          If Folder.FolderPath = "\\desired.account@domain.ca\Junk Email" Then
                              Set objJunkFolder = Folder
                          End If
                          If Folder.FolderPath = "\\desired.account@domain.ca\Inbox" Then
                             Set objInboxFolder = Folder
                          End If
                          If Folder.FolderPath = "\\desired.account@domain.ca\Random Custom Folder" Then
                              Set objRandomFolder = Folder
                          End If
  
                      Next
  
                  End If
  
              ' Now we have everything identified lets move emails!
  
              For dblCount = objJunkFolder.Items.Count To 1 Step -1
                  Set objVariant = objJunkFolder.Items.Item(dblCount)
                  DoEvents
                  If objVariant.Class = olMail Then
  
                      Set objCurrentEmail = objVariant                
  
                      objCurrentEmail.Categories = "Red Category"
                      objCurrentEmail.Move objInboxFolder
  
                  End If
              Next
          End If
      Next
  
  End Sub
  </code></pre>