1
votes

I'm trying to extract emails from a group/shared mailbox in Outlook using the code below in Excel.

olObjNs.GetSharedDefaultFolder(olShareName, olFolderInbox)

Using this I can extract inbox items.

https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/namespace-getshareddefaultfolder-method-outlook says "..... olFolderSentMail cannot be specified for this argument."

How do I get 'Sent items' from a shared mailbox?

I tried olObjNs.GetDefaultFolder(olFolderSentMail) but it retrieves my personal email 'Sent Items'.

2
Do you get any errors or exceptions when the olFolderSentMail argument is used for the GetSharedDefaultFolder function?Eugene Astafiev
Is adding the mailbox as a delegate store to the current profile an option?Dmitry Streblechenko
If fldr(iArr) = "Inbox" Then Set olObjFolder = olObjNs.GetSharedDefaultFolder(olShareName, olFolderInbox) ElseIf fldr(iArr) = "Sent Items" Then 'Set olObjFolder = olObjNs.GetDefaultFolder(olFolderSentMail) Set olObjFolder = olObjNs.GetSharedDefaultFolder(olShareName, olFolderSentMail) End If tCnt = olObjFolder.Items.Count ' taking the total count of mailitems in the folderJz Worx
There was an error yesterday, but I cannot reproduce it now. The code is shown above. Now it is showing error in the last line....... tCnt = olObjFolder.Items.Count...."Run-time error '-2147221233 (8004010f): The operation failed."....Also when I checked the variable ?olObjFolder in the immediate window, it shows..."Run-time error '-2147221233 (8004010f): The attempted operation failed.An object could not be found."Jz Worx
Has anyone resolved how we can do this without delegating mailbox? Are there other APIs that can do this job?TyCox94

2 Answers

0
votes

You can find the shared store, for example by using the following code:

olObjNs.GetSharedDefaultFolder(olShareName, olFolderInbox).Store

And then use the GetDefaultFolder method of the Store class from the Outlook object model. It 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.

0
votes

Just replace the shared mailbox address and given it contains "Sent Items" folder it should do:

Set objNS = olApp.GetNamespace("MAPI")
Set objOwner = objNS.CreateRecipient("[email protected]")
objOwner.Resolve
Set objOutlookFile = objNS.GetSharedDefaultFolder(objOwner, olFolderInbox).Parent.Folders("Sent Items")

worked well for me ;)