Help Required on VBA Program for sending different Excel File to Different Recipients.........

brsindhe

New Member
Joined
May 22, 2015
Messages
5
Hi,

I am trying to write a VBA Programme to attach excel file from the path based on the Subject (file name = Email Subject) and send it different recipient.

Could any one help me with the programme?

Thanks.
 

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.
Welcome to the forum can you copy the code you are currently trying to use, this will help get a better response to your question.
 
Upvote 0
Dim lastrow As Integer


Sub Mail_Workbook()


Dim oupApp As Object
Dim outMail As Object
Dim emailID As String
Dim CC As String
Dim BCC As String
Dim body1 As String
Dim body2 As String
Dim body3 As String
Dim body4 As String
Dim body5 As String
Dim body6 As String
Dim firstName As String
Dim fs As FileSearch
Dim subject As String
Dim i As Integer
Dim bodyContent As Range
Dim Attachments As String


'Set OutApp = CreateObject("Outlook.Application")
'Set outMail = OutApp.CreateItem(0)


ThisWorkbook.Worksheets("Email ID").Activate


Call last_Find_Row


For i = 2 To lastrow


Set outapp = CreateObject("Outlook.Application")
Set outMail = outapp.CreateItem(0)


ThisWorkbook.Worksheets("Control").Activate


ThisWorkbook.Worksheets("Email ID").Activate


subject = ActiveSheet.Cells(i, 6).Value
emailID = ActiveSheet.Cells(i, 1).Value
CC = ActiveSheet.Cells(i, 2).Value
BCC = ActiveSheet.Cells(i, 3).Value


firstName = ActiveSheet.Cells(i, 4).Value


ThisWorkbook.Worksheets("Email ID").Activate


If Attachments = subject Then


.Addattachments "C:\Users\praveen.sindhe\Desktop\FY14 CIS V2 & .xlsx"

ThisWorkbook.Worksheets("Body of the Letter").Activate


body1 = ActiveSheet.Range("A2").Value & " " & firstName


body2 = ActiveSheet.Range("A4").Value & " "


Strbody = body1 & "<br>" & _
body2 & "<br>"

StrBody2 = ActiveSheet.Range("A12").Value & "<br>" & _
ActiveSheet.Range("A15").Value & "<br>" & _
ActiveSheet.Range("A16").Value

If CC = "" And BCC = "" Then


With outMail


.To = emailID
.subject = subject
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & body1 & "<br>" & " " & "<br>" & body2 & "<br>" & " " & "<br>" & StrBody2
.Display


End With


ElseIf CC = "" And BCC <> "" Then


With outMail


.To = emailID
.BCC = BCC
.subject = subject
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & body1 & "<br>" & " " & "<br>" & body2 & "<br>" & " " & "<br>" & StrBody2
.Display


End With


ElseIf CC <> "" And BCC = "" Then


With outMail


.To = emailID
.CC = CC
.subject = subject
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & body1 & "<br>" & " " & "<br>" & body2 & "<br>" & " " & "<br>" & StrBody2
.Display


End With


Else


With outMail


.To = emailID
.CC = CC
.BCC = BCC
.subject = subject
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & body1 & "<br>" & " " & "<br>" & body2 & "<br>" & " " & "<br>" & StrBody2
.Display


End With


End If


Next i


Set outMail = Nothing
Set outapp = Nothing


MsgBox "Mail Sending ---->(IN-PROGRESS)<-----. Please Check Your Out Box Mails....... :)"


End Sub




Sub last_Find_Row()


lastrow = ThisWorkbook.Worksheets("Email ID").Range("A:A").Find("*", SearchOrder:=xlByRows, _
LookIn:=xlValues, SearchDirection:=xlPrevious).Row


End Sub






Sub Save_Close()


ThisWorkbook.Close True


End Sub
 
Upvote 0

Forum statistics

Threads
1,203,545
Messages
6,056,031
Members
444,840
Latest member
RazzelDazel

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