title: User defined type not defined on Outlook.Namespace from Excel VBA?
body: <p>I am trying to search for an Outlook email with a specific subject from Excel:</p>
  
  <pre><code>Sub Work_with_Outlook()
  
      Set olApp = CreateObject("Outlook.Application")
  
      Dim olNs As Outlook.Namespace
      Dim Fldr As Outlook.MAPIFolder
      Dim olMail As Variant
      Dim sir() As String
  
      Set olApp = New Outlook.Application
      Set olNs = olApp.GetNamespace("MAPI")
      Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
      Set myTasks = Fldr.Items
  
      Set olMail = myTasks.Find("[Subject] = ""*desired subject*""")
      If Not (olMail Is Nothing) Then
          sir = Split(olMail.Body, vbCrLf)
          For i = 1 To UBound(sir)
              ActiveWorkbook.Sheets("Sheet1").Cells(i, 1).Value = sir(i)
          Next i
          olMail.Delete
      End If
  
  End Sub
  </code></pre>
  
  <p>I get a error in Excel saying</p>
  
  <blockquote>
    <p>user defined type not defined</p>
  </blockquote>
  
  <p>on this line:</p>
  
  <pre><code>Dim olNs As Outlook.Namespace
  </code></pre>