Hi,
below is the code I'm using for sending email through excel.
Sub STRForm()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strbody As String
Dim srt As String
Dim strsubject As String
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Range("H1:H20")
strbody = strbody & cell.Value & vbNewLine
Next
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "G").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.CC = "person1@email.com;person2@email.com"
.Subject = Range("A2").value
.Body = strbody
.Attachments.Add ("C:\Users\Text.xls")
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
I need to add two thing in above code
1. The code should take subject line from cell value which are in column A. for example If "G5" is Yes then subject should be from "A5" cell, If "G8" is Yes then subject should be from "A8" cell and so on....How can I achieve this.
2. My data has 8 column's and I want that information should be included in email. for example If G5 is Yes then values in A5, B5, C5, D5 and F5 should be included in email for that particular recipient.
Br
below is the code I'm using for sending email through excel.
Sub STRForm()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strbody As String
Dim srt As String
Dim strsubject As String
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Range("H1:H20")
strbody = strbody & cell.Value & vbNewLine
Next
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "G").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.CC = "person1@email.com;person2@email.com"
.Subject = Range("A2").value
.Body = strbody
.Attachments.Add ("C:\Users\Text.xls")
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
I need to add two thing in above code
1. The code should take subject line from cell value which are in column A. for example If "G5" is Yes then subject should be from "A5" cell, If "G8" is Yes then subject should be from "A8" cell and so on....How can I achieve this.
2. My data has 8 column's and I want that information should be included in email. for example If G5 is Yes then values in A5, B5, C5, D5 and F5 should be included in email for that particular recipient.
Br