title: Triggering a subroutine for a shared mailbox in a macro inside Outlook 2010
body: <p>I have a code that triggers the subroutine Items_ItemAdd when emails come in. It works perfectly for my own personal email inbox. Here is the code I use, it's written in the default Outlook module called <em>ThisOutlookSession</em>:</p>
  
  <pre><code>Option Explicit
  
  Public WithEvents Items As Outlook.Items
  
  Public Sub Application_Startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
  End Sub
  
  Public Sub Items_ItemAdd(ByVal Item As Object)
    On Error GoTo ErrorHandler
  MsgBox "Replace the code for this message with your subroutine"
  ProgramExit:
    Exit Sub
  ErrorHandler:
    MsgBox Err.Number &amp; " - " &amp; Err.Description
    Resume ProgramExit
  End Sub
  </code></pre>
  
  <p>The problem is that I have tried countless ways to make this work for a shared email inbox which my boss just added me into the group. F.y.i. after he had added me to the list of users of this shared email I had to add it by <strong>File->Info->Account Settings->Account Settings->Change->More Settings->Advanced->add</strong> and there I had to write the name of the shared email-After trying all kinds of solutions to make the subroutine work for the shared email, e.g.</p>
  
  <p><a href="http://social.msdn.microsoft.com/Forums/office/en-US/b85f08f0-4f6b-4663-a75e-272350c07d2c/vba-outlook-2010-how-to-detecte-the-new-email-in-shared-mailbox?forum=outlookdev" rel="nofollow">http://social.msdn.microsoft.com/Forums/office/en-US/b85f08f0-4f6b-4663-a75e-272350c07d2c/vba-outlook-2010-how-to-detecte-the-new-email-in-shared-mailbox?forum=outlookdev</a> </p>
  
  <p><a href="http://www.slipstick.com/developer/code-samples/process-items-shared-mailbox/" rel="nofollow">http://www.slipstick.com/developer/code-samples/process-items-shared-mailbox/</a> </p>
  
  <p><a href="http://www.outlookcode.com/article.aspx?id=62" rel="nofollow">http://www.outlookcode.com/article.aspx?id=62</a> </p>
  
  <p>non of it was helpful for me because when I implement it don't get any error messages, it's like it's impossible for me to have an event triggered for this shared email inbox. My most hopeful attempt is where I figured out by using the <strong>vba debugger watch</strong> how to locate the <strong>Items</strong> for the shared email inbox and I replaced the line below:</p>
  
  <pre><code>Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
  </code></pre>
  
  <p>with a new line to point to the <em>Items</em> of the shared email inbox:</p>
  
  <pre><code>Set Items = objNS.Folders.Item(4).Items.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
  </code></pre>
  
  <p>To me it seems to be the right <strong>Items</strong> so I thought this would defiantly work, but the same story, nothing happens. The problem is, I have a code that works perfectly for my email's inbox, why can't I make it work for a shared email's inbox?</p>