title: Use an Outlook Macro to Send Files by Email
body: <p>Attaching all files of a folder to a Microsoft outlook email using a macro code</p>
  
  <pre><code>Dim fldName As String
  Sub SendFilesbuEmail()
      ' From slipstick.me/njpnx
      Dim sFName As String
  
      i = 0
  
      fldName = "C:\Users\"
  
      sFName = Dir(fldName)
  
      Do While Len(sFName) &gt; 0
          Call SendasAttachment(sFName)
          sFName = Dir
          i = i + 1
          Debug.Print fName
      Loop
  
      MsgBox i &amp; " files were sent"
  End Sub
  
  Function SendasAttachment(fName As String)
      Dim olApp As Outlook.Application
      Dim olMsg As Outlook.MailItem
      Dim olAtt As Outlook.Attachments
  
      Set olApp = Outlook.Application
      Set olMsg = olApp.CreateItem(0) ' email
      Set olAtt = olMsg.Attachments
  
      ' attach file
      olAtt.Add (fldName &amp; fName)
  
      ' send message
      With olMsg
          .Subject = "Here's that file you wanted"
          .To = "abcde@gmail.com"
          .HTMLBody = "Hi " &amp; olMsg.To &amp; ", &lt;br /&gt;&lt;br /&gt; I have attached " &amp; fName &amp; " as you requested."
          .Send
      End With
  End Function
  </code></pre>
  
  <p>I am getting 0 files sent and the document is not getting transferred to Microsoft outlook in the email</p>