Attaching all files of a folder to a Microsoft outlook email using a macro 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) > 0
Call SendasAttachment(sFName)
sFName = Dir
i = i + 1
Debug.Print fName
Loop
MsgBox i & " 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 & fName)
' send message
With olMsg
.Subject = "Here's that file you wanted"
.To = "abcde@gmail.com"
.HTMLBody = "Hi " & olMsg.To & ", <br /><br /> I have attached " & fName & " as you requested."
.Send
End With
End Function
I am getting 0 files sent and the document is not getting transferred to Microsoft outlook in the email
To Attached all files into one Email, try modifying your code.
Example.
Make sure to update
FilesPath = Environ("USERPROFILE") & "\Desktop\FolderName\"
FolderName to the correct folder name.You can also use
FilesPath = "C:\Users\Om3r\Desktop\FolderName\"
and make sure to update Om3r and FolderName