Hi,
You can try the following code sample to send all of the files in a folder as email attachments:
Dim fldName As String
Sub SendFilesbuEmail()
' From http://slipstick.me/njpnx
Dim sFName As String
i = 0
fldName = "C:\Users\Diane\"
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 = "alias@domain.com"
.HTMLBody = "Hi " & olMsg.To & ", <br /><br /> I have attached " & fName & " as you requested."
.Send
End With
End Function
Reference:
http://www.slipstick.com/developer/macro-send-files-email/
Please Note: Since the web site is not hosted
by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
Since we are not the best resource for coding, if you need further assistance about coding, I'd recommend you post a question in the following forum:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
Steve Fan
TechNet Community Support