Emailing Multiple attachments with VBA code

Puranichappal

New Member
Joined
Jun 16, 2017
Messages
1
Hi,

I am using VBA code to send multiple clients with copy to some.

It looks like below... I want to attach multiple file ....plz suggest.

**************************************************

Sub Mail_Send_withattachment()
On Error Resume Next
Dim employeename, tomailid, ccid, bccid, compname, subject, strbody, strbody1, Attachfile As String
'Don't forget to set a reference to Outlook in the VBA editor
Dim OutApp As Object
Dim OutMail As Object

Application.DisplayAlerts = True

i = 6
Sheets("Data").Select
While Sheets("Data").Range("A" & i).Value <> 0
employeename = Sheets("Data").Range("B" & i).Value
tomailid = Sheets("Data").Range("C" & i).Value
ccid = Sheets("Data").Range("D" & i).Value
'ccid = Sheets("Data").Range("B2").Value
bccid = Sheets("Data").Range("B3").Value
subject = Sheets("Data").Range("B1").Value
Attachfile = Sheets("Data").Range("B4").Value & "" & Sheets("Data").Range("A" & i).Value & ".xlsx"

strbody = "Dear " & "<b>" & employeename & " (" & Sheets("Data").Range("A" & i).Value & ")" & " ,</b><br>" & Sheets("Msg Data").Range("mainmsg").Value & "</br>"


strbody1 = "<br>" & Sheets("Msg Data").Range("signature").Value & "</br>"

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
.To = tomailid
.CC = ccid
.BCC = bccid
.subject = subject
.Attachments.Add Attachfile
.HTMLBody = strbody & strbody1
'.Display
.Send
End With

Set OutMail = Nothing
Set OutApp = Nothing

Sheets("Data").Select
Sheets("Data").Range("E" & i).Value = "=TEXT(NOW(),""DD-MMM-YY hh:mm:ss am/pm"")"
Sheets("Data").Range("E" & i).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False


i = i + 1


Wend


End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Just add in more
Code:
.Attachments.Add
lines under the current one in your code. You can either add new variables to hold the file path or just reference it direct

Code:
.Attachments.Add  "C:\Myfile.txt"
or

.Attachments.Add [COLOR=#333333]Sheets("Data").Range("B4").Value & "" & Sheets("Data").Range("A" & i).Value & ".xlsx"[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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