title: Set reference to Outlook 365 folder in Excel VBA
body: <p>My company is transferring from Outlook 16 to Outlook 365, and the Excel VBA script below now needs to refer to a mailbox in Outlook 365.</p>
  
  <p>It errors on the line </p>
  
  <pre><code>Set oMapi = oApp.GetNamespace("MAPI").Folders(strMail).Folders("inbox")
  </code></pre>
  
  <p>with the error </p>
  
  <blockquote>
    <p>The attempted operation failed. An object could not be found.</p>
  </blockquote>
  
  <p>Is it possible the mailbox needs to be added in a different way? Or is there a different way to do this function in Outlook 365?</p>
  
  <p>I am not seeing much on a different way to do this with Outlook 365.</p>
  
  <pre><code>Sub Import_Email_Preferences()
      Const strMail As String = "borrowerservicesshiftbid@glhec.org"
      Dim oApp As Outlook.Application
      Dim oMapi As Outlook.MAPIFolder
      Dim oMail As Outlook.MailItem
      Dim strEmailAddress As String
      Dim strSenderName As String
      Dim strSubject As String
      Dim intRow As Integer
  
      Dim i As Long
      Dim tbl As ListObject
      Dim ltblRow As Long
      Set tbl = ThisWorkbook.Worksheets("Preferences").ListObjects(1)
      ltblRow = tbl.DataBodyRange.Rows.Count
  
      On Error Resume Next
      Set oApp = GetObject(, "OUTLOOK.APPLICATION")
          If (oApp Is Nothing) Then Set oApp = CreateObject("OUTLOOK.APPLICATION")
      On Error GoTo 0
  
      'Getting Error Here
      Set oMapi = oApp.GetNamespace("MAPI").Folders(strMail).Folders("inbox")
  
      For i = oMapi.Items.Count To 1 Step -1
          Set oMail = oMapi.Items(i)
  
          If TypeOf oMail Is Outlook.MailItem Then
              MsgBox = "Blue"
          End If
      Next i
  
      Set oApp = Nothing
      Set oMapi = Nothing
      Set oMail = Nothing
      Set oHTML = Nothing
      Set oElColl = Nothing
  End Sub
  </code></pre>