Draft outlook emails using excel and attach multiple files within same folder using partial name

shiva1111

New Member
Joined
Nov 18, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi Sir,

I am quite new to VBA code and have written the below code to generate outlook emails as drafts with attachments and this works fine for single attachment with excact filename.
However my requirement is to attach multiple files using partial name within the same folder. The partial name would be different for different emails.

Public Sub DraftOutlookEmails()
'Microsoft Outlook XX.X Object Library is required to run this code
'Variable declaration
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
Dim lCounter As Long
'Set objects
Set objOutlook = Outlook.Application
'Read details from Excel sheet and draft emails
For lCounter = 6 To 8 'You can change the counter as per requirement
'Create a new email item
Set objMail = objOutlook.CreateItem(olMailItem)
'To
objMail.To = Sheet1.Range("A" & lCounter).Value
'Cc
objMail.CC = Sheet1.Range("B" & lCounter).Value
'Subject
objMail.Subject = Sheet1.Range("C" & lCounter).Value
'Email Body
objMail.Body = Sheet1.Range("D" & lCounter).Value
'Add Attachment
objMail.Attachments.Add (Sheet1.Range("E" & lCounter).Value)
'Draft email
objMail.Close (olSave)
'Close the object
Set objMail = Nothing
Next
'Show confirmation message to user
MsgBox "Done", vbInformation
End Sub




Please help me
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top