0

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("ch-heaphq05test@xyz.com").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
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Mani233
  • 1
  • 2
  • Do you mean a shared mailbox? What exactly do you mean saying `generic mailbox`? – Eugene Astafiev Mar 28 '22 at 22:41
  • Does this answer your question? [Get reference to additional Inbox](https://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton Sep 20 '22 at 11:07

1 Answers1

0

If you have the right to access the mailbox and folder in question, use Namespace.GetSharedDefaultFolder instead of Namespace.GetDefaultFolder above.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78