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
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