I have an excel sheet with a table containing all the members subscriptions details. And every time a member renews his subscription, I need to send email with his membership details to all the team
I had for info. and to print him a new ID.
I had a code in other sheet to send the sheet but I don't know how to modify it to do what I need.
what I need is to include dynamic cells in both of subject and email body as follows:
1- In the Subject I need to include the membership No. in Col "B" which is different every time
2- In the email. body as you can see in image 2 I need to include the membership No. Again in addition to start date in cell "J8" and - to the end date in cell K8
this is how the email should be: if I'm sending email for membership No1 in row No 8 as you can see in the screenshot
Subject: Renewed memership No. (dynamic cell) "B8"
Dear Team
kindly find attached the renewed membership No. ("B8") for the period from (Cell "J8") -dynamic cell- to (Cell "k8") - dynamic cell
please print a new ID according to the details
best Regards
My Outlook Signature
(this code was created on this platform by Mr. @John_w )
I had for info. and to print him a new ID.
I had a code in other sheet to send the sheet but I don't know how to modify it to do what I need.
what I need is to include dynamic cells in both of subject and email body as follows:
1- In the Subject I need to include the membership No. in Col "B" which is different every time
2- In the email. body as you can see in image 2 I need to include the membership No. Again in addition to start date in cell "J8" and - to the end date in cell K8
this is how the email should be: if I'm sending email for membership No1 in row No 8 as you can see in the screenshot
Subject: Renewed memership No. (dynamic cell) "B8"
Dear Team
kindly find attached the renewed membership No. ("B8") for the period from (Cell "J8") -dynamic cell- to (Cell "k8") - dynamic cell
please print a new ID according to the details
best Regards
My Outlook Signature
(this code was created on this platform by Mr. @John_w )
VBA Code:
Public Sub Send_Email()
Dim outApp As Object 'Outlook.Application
Dim outMail As Object
Dim newHTML As String
Dim ws As Object
Dim HTML As String, p1 As Long, p2 As Long
Dim filename As String, Body As String, body2 As String, body3 As String, body4 As String
Dim ToEmail As String, CCEmail As String, myDate As String
With ActiveSheet
filename = .Range("R8").Value
ToEmail = .Range("R9").Value
CCEmail = .Range("R10").Value
Body = .Range("VR11").Value
body2 = .Range("R12").Value
body3 = .Range("R13").Value
body4 = .Range("R14").Value
End With
Dim Path As String, fname As String
Path = "D:\Desktop\Guards\gurads list.xlsm"
fname = filename & " - " & Date
myDate = Format(Now(), "yyyy/MM/dd")
newHTML = "<p> Dear All,</p>" & _
"<p>" & body2 & myDate & _
"<p>" & body3 & "</p>" & "</p>" & _
"<p>" & body4 & "</p>"
Set outApp = CreateObject("Outlook.Application")
Set outMail = outApp.CreateItem(0)
'Read the default signature HTML in a new email
With outMail
.GetInspector
HTML = .HTMLbody
End With
'Remove first 2 <p> tags in HTMLbody. In Outlook 2016 and higher both these contain only , resulting in blank paragraphs
p1 = InStr(1, HTML, "<p ", vbTextCompare)
p2 = InStr(p1 + 1, HTML, "<p ", vbTextCompare)
p2 = InStr(p2, HTML, "</p>")
HTML = Left(HTML, p1 - 1) & Mid(HTML, p2 + Len("</p>"))
'Find end of opening body tag and insert new HTML after it
p1 = InStr(1, HTML, "<body", vbTextCompare)
p1 = InStr(p1, HTML, ">")
HTML = Left(HTML, p1) & newHTML & Mid(HTML, p1 + 1)
'Create and send the HTML email
With outMail
.To = ToEmail
.CC = CCEmail
.Subject = filename & " " & myDate
.HTMLbody = HTML
.Attachments.Add "D:\Desktop\Guards\gurads list.xlsm"
.Display
'.Send
End With
Set outMail = Nothing
Set outApp = Nothing
End Sub