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!
 
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.
Similar threads
Thread starter Title Forum Replies Date
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
F Outlook 2016 Email with attachments not being received Using Outlook 2
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
T Outlook converts sent email to txt attachments when sync Using Outlook 0
Dan_W Nested email attachments Outlook VBA and Custom Forms 4
M Print email and, attachments sent in hyperlinks in the email Outlook VBA and Custom Forms 2
W Save and rename outlook email attachments to include domain name & date received Outlook VBA and Custom Forms 4
G Download pdf attachments only if email subject has one of words Outlook VBA and Custom Forms 8
I Forwarding attachments in email received Outlook VBA and Custom Forms 3
A Outlook - Send New 20 Attachments through Email Using Outlook 4
C Auto save outlook attachments when email is received Outlook VBA and Custom Forms 1
C Rule To Save attachments on receipt of email Outlook VBA and Custom Forms 2
Diane Poremsky Add Attachments and Set Email Fields During a Mail Merge Using Outlook 0
G VBA Copy draft email to a new email - attachments not copided Using Outlook 7
Diane Poremsky Add attachments and set email fields during a mail merge to email Using Outlook 0
M VBA code to save email attachments (PDF) as email subject line Outlook VBA and Custom Forms 1
T Saving Outlook 2010 email with attachments but read the email without Outlook Using Outlook 2
L Auto printing unread email + attachments in Inbox - Outlook 2010 - (New user) Using Outlook 1
C Visual Basic auto create task from email including attachments Using Outlook 9
G archive attribute for email attachments Using Outlook 2
H outlook email merging with attachments Using Outlook 4
R BCM: Email attachments are not shown BCM (Business Contact Manager) 4
M Outlook 2010 and how to get attachments listed when creating a new email? Using Outlook 1
5 Automatically print email attachments Using Outlook 7
R Auto Reply with Original Email and any attachments Outlook VBA and Custom Forms 1
K Mail Merge to email with attachments Outlook VBA and Custom Forms 8
H Storing an email along with its attachments? Outlook VBA and Custom Forms 1
C Persist the email format and attachments / images while replying A Outlook VBA and Custom Forms 5
Z Re: Auto Print email and word attachments on send Outlook VBA and Custom Forms 1
T How do I search email attachments Outlook VBA and Custom Forms 2
L Outlook attachments from OneDrive as links Using Outlook 0
R Saving Emails and Attachments as .msg file Using Outlook 3
KurtLass Opening Graphics Attachments in Outlook 2021 Using Outlook 0
Commodore PDF attachments started to open in Edge Using Outlook 0
T Outlook 2021 Cannot open attachments Outlook DeskTop 2021 Using Outlook 0
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
A Attachments.Delete Outlook VBA and Custom Forms 3
M Deleting attachments does not reduce file size Using Outlook 0
L unblocking attachments before sending Office 365 Advanced Protection Using Outlook 0
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
R Use an ItemAdd to Save Attachments on Arrival Outlook VBA and Custom Forms 0
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
R fetching blocked attachments Outlook VBA and Custom Forms 0
H Outlook 2016 sent over 30 copies of an e-mail with attachments Using Outlook 1
W Automatically open attachments without automatically printing them Using Outlook 0
O Save attachments using hotkey without changing attributes Outlook VBA and Custom Forms 1

Similar threads

Back
Top