I'm currently using the following code in Excel to access folders in an unmanned Outlook mailbox other than my own.
However is there a way I can set the folder in the code rather than using the folder picker.
Sub Launch_Pad()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
n = 2
Cells.ClearContents
Call ProcessFolder(olFolder)
Set olNS = Nothing
Set olFolder = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub
Sub ProcessFolder(olfdStart As Outlook.MAPIFolder)
Dim olFolder As Outlook.MAPIFolder
Dim olObject As Object
Dim olMail As Outlook.MailItem
n = 1
For Each olObject In olfdStart.Items
If TypeName(olObject) = "MailItem" Then
n = n + 1
Set olMail = olObject
Cells(n, 1) = olMail.Subject
Cells(n, 2) = olMail.ReceivedTime
Cells(n, 3) = olMail.Body
End If
Next
Set olMail = Nothing
Set olFolder = Nothing
Set olObject = Nothing
End Sub
Work with GetSharedDefaultFolder Method to get access to another user for one or more of their default folders.
Example here is shared Inbox
Thanks Erdem
If the folder should be the inbox you can use below
Or for a subfolder