'How to connect to Generic Mailbox Inbox and subfolders?
I have code to connect my default inbox in outlook.
I am not able to connect to a generic mailbox inbox. Please could someone review the code and help on this issue.
Dim olApp As Outlook.Application, olNs As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder, olMail As Outlook.MailItem
Dim eFolder As Outlook.folder '~~> additional declaration
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim objAtt As Outlook.Attachment
Dim olItem As Outlook.MailItem
Dim olReply As MailItem ' Reply
Dim olRecip As Recipient
Dim i As Long
Dim x As Date, ws As Worksheet '~~> declare WS variable instead
Dim lrow As Long '~~> additional declaration
Dim collItems As New Collection
Dim MovecollItems As New Collection
Set ws = ActiveSheet '~~> or you can be more explicit using the next line
Set EC = ThisWorkbook.Sheets("Email Search Criteria")
Set IE = ThisWorkbook.Sheets("Inbox Emails")
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)'ABC.com "My default Email Folder"
Set Inbox_1 = olNs.Folders("[email protected]").Folders("Inbox") 'Problem is over here.
'Set IB_SubFolder = Inbox_1.Folders("Inbox")
'Set RE_SubFolder = Inbox_1.Folders("Rejected Emails")
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/hv5uA.png
Solution 1:[1]
If you have the right to access the mailbox and folder in question, use Namespace.GetSharedDefaultFolder
instead of Namespace.GetDefaultFolder
above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitry Streblechenko |