I would like to setup a listener in the group folder of my outlook. The way it should work is that whenever I get an email there a message box pops out. By 'group folder' I mean the folder as seen below:
I have successfully managed to perform the task with the default inbox folder using the code below, however I am really struggling to find a way to do it for the group folder:
Private WithEvents inboxItems As Outlook.Items
' Setup listener to Inbox
Private Sub Application_Startup()
Dim outlookApp As Outlook.Application
Dim objectNS As Outlook.NameSpace
Dim ShareInbox As Outlook.MAPIFolder
Dim outlookRecip As Outlook.Recipient
Set outlookApp = Outlook.Application
Set objectNS = outlookApp.GetNamespace("MAPI")
Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
' Set outlookRecip = objectNS.CreateRecipient("[email protected]")
' Set inboxItems = objectNS.GetSharedDefaultFolder(outlookRecip, olFolderInbox)
End Sub
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
MsgBox ("Hi")
End Sub
The closest that I have gotten is by following the advice from this post which I have implemented on the two commented lines on my code above. However when I uncomment these two lines and run the code I get the following error:
The server mailbox cannot be opened because this address book entry is not a mail user
CodePudding user response:
Group calendars are not exposed for the programmatic access. On the low level, all group calendars are stored in a separate OST file.
CodePudding user response:
Try to use the olPublicFoldersAllPublicFolders value for the GetDefaultFolder
method.
It it doesn't work then you need to iterate over Folders tree to get the right folders. For example, you may find the Enumerate folders article helpful. If they are located in the same store in Outlook. If not, you may iterate over the NameSpace.Stores collection that represents all the Store objects in the current profile.