title: Excel VBA Error "user-defined type not defined" with Outlook
body: <p>I am using Office 2016 in my computer and I have a VBA code that sends Email to so mail lists in the file. Every time I want to send the Emails automatically with my CommandButton, I get the error massage:  "user-defined type not defined".
  I made some research in the web and I found out that there is a solution:
  VB Editor ----> Tools ----> Referenced ----> Microsoft Outlook 16.0 Object Library</p>
  
  <p><strong>But</strong>
  the next time I open the file the same error runs again and again and again. Can someone find me solution that will be permanent? I Don't know what to do more then I already did.</p>
  
  <pre><code>Public Sub sendMail()
      Call ini_set
  
      If mail_msg.Cells(200, 200) = 1 Then
          lr = main_dist.Cells(main_dist.Rows.Count, "A").End(xlUp).row
  
          On Error Resume Next
          For i = 2 To lr
  
              Application.DisplayAlerts = False
              Dim applOL As Outlook.Application
              Dim miOL As Outlook.MailItem
              Dim recptOL As Outlook.Recipient
              mail_msg.Visible = True
              mailSub = mail_msg.Range("B1")
              mailBody = mail_msg.Range("B2")
              mail_msg.Visible = False
              Set applOL = New Outlook.Application
              Set miOL = applOL.CreateItem(olMailItem)
              Set recptOL = miOL.Recipients.Add(main_dist.Cells(i, 5))
              recptOL.Type = olTo
  
              tempPath = ActiveWorkbook.Path &amp; "\" &amp; main_dist.Cells(i, 4) &amp; ".xlsm"
  
              With miOL
                  .Subject = mailSub
                  .Body = mailBody
                  .Attachments.Add tempPath
                  .send
  
              End With
              Set applOL = Nothing
              Set miOL = Nothing
              Set recptOL = Nothing
              Application.DisplayAlerts = True
  
  
          Next i
  End Sub
  </code></pre>
  
  <p>Here is the problem based on the VB Editor:</p>
  
  <pre><code>Dim applOL As Outlook.Application
  </code></pre>