PDA

View Full Version : Accessing Emails in a public group (Outlook 2016)



BenjaminDana
03-20-2017, 07:25 AM
Howdy everyone,

My company recently upgraded to Microsoft 365 (2016 edition). After the change my coworkers and I decided to create a new public group.

This is working out swell, but I have a program that used to run through a person's inbox and open up emails based on the subject line. Trying to adapt this to work with the public group folder has led me to a stopping point.




Sub OpenGroupEmails()
Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient
Dim fldr As Outlook.MAPIFolder

Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("MI Team")
objOwner.Resolve

If objOwner.Resolved Then
MsgBox objOwner.Name
Set fldr = NS.GetSharedDefaultFolder(objOwner, olPublicFoldersAllPublicFolders)
End If
End Sub

The group name is "MI Team", when I run this I get a message box with the words "MI Team". But the next line gives me the following error "Run-time error '-2147024809 (80070057)': Sorry, something went wrong. You may want to try again."

I feel like I'm missing something simple that will resolve this issue.

Thanks for taking the time to look over my problem. God bless. :)

skatonni
03-20-2017, 03:53 PM
It looks like you have a shared mailbox. If so, the code should look like this with olFolderInbox rather than olPublicFoldersAllPublicFolders


Sub OpenGroupEmails()
Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient
Dim fldr As Outlook.MAPIFolder

Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("MI Team")
objOwner.Resolve

If objOwner.Resolved Then
MsgBox objOwner.Name
Set fldr = NS.GetSharedDefaultFolder(objOwner, olFolderInbox)
End If
End Sub

If there is a public folder involved then there is an example in "Folders.Item Method (Outlook)"

https://msdn.microsoft.com/en-us/library/office/ff867877.aspx


Sub OpenPublicFolder()

Dim objFolder As Folder

Set objFolder = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders.("name of folder")

Set ActiveExplorer.CurrentFolder = objFolder

End Sub