title: Only valid in object module
body: <p>I'm getting this error:</p>
  
  <blockquote>
    <p>only valid in object module  </p>
  </blockquote>
  
  <p>when I'm trying to run the script below on VBA outlook 2016. </p>
  
  <pre><code>Private WithEvents myItem As outlook.MailItem
  
  Private Sub myItem_AttachmentRead(ByVal myAttachment As Outlook.Attachment)
  
   If myAttachment.Type = olByValue Then
  
   MsgBox "If you change this file, also save your changes to the original file."
  
   End If
  
  End Sub
  
  
  Public Sub TestAttachRead()
  
   Dim atts As Outlook.Attachments
  
   Dim myAttachment As Outlook.Attachment
  
   Set myItem = Application.ActiveExplorer.CurrentFolder.Items("Test")
  
   Set atts = myItem.Attachments
  
   myItem.Display
  
  End Sub
  </code></pre>