Attachments to New email item

Status
Not open for further replies.

suhasjose

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Can someone please help me out with this? I have almost 150 pdf files in a folder and i want to email them to a common email address based on the file names. For example; There are files names as - 1000,1000#1,1000#2,2000,3000,41000,41000#1 - Here I need to send every files with same name before "#" in one email. In this example files -1000,1000#1,1000#2 -should go in one email, 2000 should go in another email, 3000 should go in another email and 41000,41000#1 should go in another email. I have been able to send each file in th efolder in seperate emails, but I couldn't figure out how to attach files in the above said manner.. I am trying to automate outlook to do this task.

Thanks in advance for your valuable advices!
 
Outlook version
Outlook 2007
Email Account
Exchange Server
Sub AddFiles()
Dim StrFolder, StrFile, StrFiles(200), StrSearch As String
Dim i, j As Integer
Dim myMailItem As MailItem
'Select FOLDER and save all file name in an array
StrFolder = "C:\New Folder" ' CHANGE THE FOLDER
StrFile = Dir(StrFolder & "\*")
Do While Len(StrFile) > 0
i = i + 1
StrFiles(i) = StrFile
StrFile = Dir
Loop
'Loop through the array, upon finding a filename with 4 characters, loop through the aray again and find similar files
For j = 1 To i
If Len(StrFiles(j)) = 8 Then ' eg 1000.pdf - 8 characters
Set myMailItem = Application.CreateItem(olMailItem)
StrSearch = Left(StrFiles(j), 4) ' eg 1000 - first 4 characters
For k = 1 To i
If Left(StrFiles(k), 4) = StrSearch Then
MsgBox StrFiles(k)
myMailItem.Attachments.Add StrFolder & "\" & StrFiles(k)
End If
Next
myMailItem.To = "ADD RECIPIENTS"
myMailItem.Display ' Change to .send after testing
End If
Next

End Sub
 
Status
Not open for further replies.
Top