I found some scripts in internet and combined everything together after making a few changes.. It works perfect now! The only problem that I face now is it skips file names if the name begins with a zero.
Thanks again Diane for your assistance..
---------------------------Dim strName As String
Sub SendFilesbyEmail()
Call ReadFiles("C:\Users\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
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, Len(strName) - 4) = Left(strName, Len(strName) - 4) Then
olAtt.Add fldName & fName
sAttName = fName & "<br /> " & sAttName
End If
'Debug.Print fName
fName = Dir
Loop
' send message
With olMsg
.Subject = "Here's that file you wanted" & fName
.To = "alias@domain.com"
.HTMLBody = "Hi " & olMsg.To & ", <br /><br /> I have attached <br /> " & sAttName & "as you requested."
.Display
End With
sAttName = ""
'Next i
End Function
Function ReadFiles(MyFile As String)
Dim Counter As Long
ReDim DirectoryListArray(1000)
MyFile = Dir$(MyFile)
Do While MyFile <> "" And InStr(1, MyFile, "#") = 0
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop
ReDim Preserve DirectoryListArray(Counter - 1)
For Counter = 0 To UBound(DirectoryListArray)
strName = DirectoryListArray(Counter)
Debug.Print strName
Call SendFilesArray("C:\Users\Test\")
Next Counter
End Function