title: How can I extract the email address for a store?
body: <p>In my company we have a number of different email addresses which go to &quot;Shared Inbox&quot; accounts that are managed by a few people.</p>
  <p>We want to keep track of how many emails are in each Inbox.</p>
  <p>A user might look after several different shared inboxes, and no one user has access to the same set of inboxes.</p>
  <p>The VBA code I have loops through all of the logged-in user's shared inboxes and counts how many emails are in each inbox folder which isn't their own &quot;personal&quot; inbox and logs that data to a table using a separate procedure:</p>
  <pre class="lang-vb prettyprint-override"><code>Sub WorkPosition()
  
      Dim ThisUser As String
      Dim Mailbox As Object
      Dim MailBoxName As String
      Dim oStore As Outlook.Store
      Dim olFolder As Outlook.Folder
  
      ThisUser = UCase(Environ(&quot;UserName&quot;))
  
      For x = Application.Session.Stores.Count To 1 Step -1
          Set Mailbox = Nothing
          On Error Resume Next
          Set Mailbox = Application.Session.Stores(x)
          On Error GoTo 0
          If Mailbox Is Nothing Then GoTo SkipMailbox
          MailBoxName = Mailbox
          If InStr(UCase(Mailbox), ThisUser) = 0 Then
              Set olFolder = Mailbox.GetDefaultFolder(olFolderInbox)
              Set objItems = olFolder.Items
              MailCount = objItems.Count
              LogFolder MailBoxName, MailCount, ThisUser 'Run the &quot;Logfolder&quot; sub which logs the data
          End If
      SkipMailbox:
      Next x
  
  End Sub
  </code></pre>
  <p>This all works, except users don't name their shared inbox accounts very well. Several users have the same name for their shared inbox, but they're associated to different email addresses.</p>
  <p>For example:</p>
  <ul>
  <li>Charles might have <strong>info@mycompany.com</strong> as an Outlook store named &quot;Customer Questions&quot;</li>
  <li>David might have <strong>queries@mycompany.com</strong> as an Outlook store also named &quot;Customer Questions&quot;</li>
  </ul>
  <p>When Charles and David log their mail counts using my VBA code, they are both being logged with the MailBoxName as &quot;Customer Questions&quot;.</p>
  <p>I've come to the conclusion that I don't want to log the mailbox name. I want to log the email address instead, which they can't change and will be unique to that inbox.</p>
  <p>I am able to do this if there is an email in the inbox, since I can just take the &quot;to&quot; address from the first mail item in the folder, but not if there are 0 emails in the folder.</p>
  <p>How can I extract the incoming email address(es) which are associated to a user's Outlook store into a VBA string, so that I can pass it to my &quot;LogFolder&quot; procedure?</p>