-1

Hello i have this perfect code i found. It checks for new messages and it adds in a custom column ONLY the date and no time. It is perfect for Grouping by Received and then from.

But it works only in my default account, Can this works it multiple accounts?

Private Sub Application_Quit()
    Set myInbox = Nothing
End Sub

Private Sub Application_Startup()
    Set myInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items

End Sub

Private Sub myInbox_ItemAdd(ByVal Item As Object)
    Item.UserProperties.Add "DateReceived", olDateTime
    Item.UserProperties.Item("DateReceived") = DateValue(Item.ReceivedTime)
    Item.Save
End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • See here: http://stackoverflow.com/questions/33953386/vba-to-select-mailbox-if-an-account-has-multiple-mailboxs – OpiesDad Sep 19 '16 at 18:44
  • 2
    Possible duplicate of [Get reference to additional Inbox](http://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton Sep 19 '16 at 19:08
  • As well http://stackoverflow.com/questions/26274516/vba-get-email-from-non-default-inbox and http://stackoverflow.com/questions/6849068/get-inboxes-from-outlook – niton Sep 19 '16 at 19:09
  • Yes i allready have read them, but i can not fix it to work for my sitiation, maybe can you give me a boost?? – Nikos Milonas Sep 19 '16 at 19:28

1 Answers1

0

The existing code works for the default Inbox folder due to the following line of code:

  Set myInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items

Instead, you need to iterate over all stores in the profile and call the GetDefaultFolder method of the Store class which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

The Stores property of the Namespace class returns a Stores collection object that represents all the Store objects in the current profile.

Finally, you may find the Working with Outlook Accounts, Stores, Folders and Items article helpful.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45