title: How to attach a file to a message?
body: <p>I need to attach files from a directory. I have tried multiple commands.</p>
  <p>The outlook msg is saved in the folder but without attachment and I need to attach it.</p>
  <p>Here is a part of my code.</p>
  <pre class="lang-vb prettyprint-override"><code>Dim filename, file As String
  Dim folder, path As String
  
  filename = folderpath &amp; &quot;\sheets\&quot;
  file = Dir(filename &amp; x &amp; &quot;*.xlsx&quot;)
  
  Dim ObjMsg As Object
   
  'Create email
  On Error Resume Next
  Set olapp = GetObject(, &quot;Outlook.Application&quot;)
  If Err.Number = 429 Then
      Set olapp = CreateObject(&quot;Outlook.application&quot;)
      DoEvents
  End If
  On Error GoTo 0
  
  Set ObjMsg = olapp.CreateItem(olMailItem)
  DoEvents
   
  ObjMsg.To = &quot;&quot;
  ObjMsg.CC = &quot;&quot; 
  ObjMsg.Subject = &quot;&quot;
    
  ObjMsg.BodyFormat = 3 'Set richtext format
  Set editor = ObjMsg.GetInspector.WordEditor
  editor.Content.Paste
  wd.Quit SaveChanges:=False
  
  While Len(file) &gt; 0
      ObjMsg.Attachments.Add (filename &amp; file)
      file = Dir
  Wend
  </code></pre>