AmirFirdaus9509
New Member
- Joined
- Feb 14, 2022
- Messages
- 19
- Office Version
- 2016
- Platform
- Windows
Hi All ,
I need your expertise in how to send Email based on a table. I have a table that contain user name , email , cc , subject and location.
I would like to filtered out location and expect the macro to loop in the filtered row instead of capturing all row when i pressed the "Send Email" button . As shown in the image below , I would like it to send out detail on Row 5 and 10 where I would expect only 2 email draft. But the macro is capturing all row from 2 to 10 and giving out 9 Email Draft.
Below i have attached a macro that i am using .
Sub send_mass_email()
Dim i As Integer
Dim name, email, body, subject, copy, place, business As String
Dim OutApp As Object
Dim OutMail As Object
Dim cel As Range
body = ActiveSheet.TextBoxes("TextBox 1").Text
i = 2
'Loop down name column starting at row 2 column 1
Do While Cells(i, 1).Value <> ""
name = Split(Cells(i, 1).Value, " ")(0) 'extract first name
email = Cells(i, 2).Value
subject = Cells(i, 3).Value
copy = Cells(i, 4).Value
business = Cells(i, 5).Value
place = Cells(i, 6).Value
'replace place holders
body = Replace(body, "C1", name)
body = Replace(body, "C5", business)
body = Replace(body, "C6", place)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = email
.cc = copy
.subject = subject
.body = body
'.Attachments.Add ("") 'You can add files here
.display
'.Send
End With
'reset body text
body = ActiveSheet.TextBoxes("TextBox 1").Text
i = i + 1
Loop
Set OutMail = Nothing
Set OutApp = Nothing
MsgBox "Email(s) Created!"
End Sub
Thank you very much
I need your expertise in how to send Email based on a table. I have a table that contain user name , email , cc , subject and location.
I would like to filtered out location and expect the macro to loop in the filtered row instead of capturing all row when i pressed the "Send Email" button . As shown in the image below , I would like it to send out detail on Row 5 and 10 where I would expect only 2 email draft. But the macro is capturing all row from 2 to 10 and giving out 9 Email Draft.
Below i have attached a macro that i am using .
Sub send_mass_email()
Dim i As Integer
Dim name, email, body, subject, copy, place, business As String
Dim OutApp As Object
Dim OutMail As Object
Dim cel As Range
body = ActiveSheet.TextBoxes("TextBox 1").Text
i = 2
'Loop down name column starting at row 2 column 1
Do While Cells(i, 1).Value <> ""
name = Split(Cells(i, 1).Value, " ")(0) 'extract first name
email = Cells(i, 2).Value
subject = Cells(i, 3).Value
copy = Cells(i, 4).Value
business = Cells(i, 5).Value
place = Cells(i, 6).Value
'replace place holders
body = Replace(body, "C1", name)
body = Replace(body, "C5", business)
body = Replace(body, "C6", place)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = email
.cc = copy
.subject = subject
.body = body
'.Attachments.Add ("") 'You can add files here
.display
'.Send
End With
'reset body text
body = ActiveSheet.TextBoxes("TextBox 1").Text
i = i + 1
Loop
Set OutMail = Nothing
Set OutApp = Nothing
MsgBox "Email(s) Created!"
End Sub
Thank you very much