Sub SendFilesbyEmail()
Call SendFilesArray("C:\Users\diane\Test\")
End Sub
Function SendFilesArray(fldName As String)
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem
Dim olAtt As Outlook.Attachments
Dim fName As String
Dim sAttName As String
Dim arrName As Variant
Dim strName As String
Set olApp = Outlook.Application
arrName = Array("2012", "2013", "2014")
' Go through the array and look for a match, then do something
For i = LBound(arrName) To UBound(arrName)
strName = arrName(i)
Set olMsg = olApp.CreateItem(0) ' email
Set olAtt = olMsg.Attachments
fName = Dir(fldName)
Do While Len(fName) > 0
If Left(fName, 4) = strName Then
olAtt.Add fldName & fName
sAttName = fName & "
" & sAttName
End If
Debug.Print fName
fName = Dir
Loop
' send message
With olMsg
.Subject = "Here's that file you wanted"
.To = "alias@domain.com"
.HTMLBody = "Hi " & olMsg.To & ",
I have attached
" & sAttName & "as you requested."
.Display
End With
sAttName = ""
Next i
End Function