VBA email to pick up particular cell values

Status
Not open for further replies.

VBAstudent1986

New Member
Joined
Jan 8, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
IN the macro below, I am looking to fill in cell values (marked XXXX below) into the body of the email.

Need help with the cell referencing.

Each XXXX should refer to a particular value in the excel sheet. Any help would be great!!


Sub send_Email()

Dim i As Long, j As Long, k As Long
i = 6
' k = 3
'j = 5

Do While i <= 6

Dim outlookOBJ As Object
Dim mItem As Object
Dim strbody As String

Set outlookOBJ = CreateObject("outlook.application")
Set mItem = outlookOBJ.CreateItem(olmailItem)



On Error Resume Next



strbody = "<BODY style = font-size:12pt; font-family:Arial>" & _
"Dear XXXX,<P>" & vbNewLine & vbNewLine & _
"Thank you for being a valued XXXX customer. <P> " & vbNewLine & vbNewLine & _
"We have discovered that your XXXX vehicle was incorrectly registered Please correct it from your end & _

With mItem
.sentonbehalfofname = Sheets("Data").Cells(i, "M").Value
.To = Sheets("Email").Cells(i, "F").Value
' .cc = Sheets("Email").Cells(i, "I").Value
' .bcc = Sheets("Email").Cells(i, "f").Value
.Subject = "Vehicle was incorrectly registered"

.Display
.HTMLBody = strbody & _
"<img src='D:\Nov 2020\MMFS\mmfslogo.jpg' height='20%' > " & _
.HTMLBody

.send

Sheets("Email").Cells(i, "N").Value = "Email Sent"

End With


' Sheets("Email").Cells(i, "N").Value = "Missing attachments"


i = i + 1
j = j + 1
k = k + 1

Loop

MsgBox " Email macro is complete"
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Status
Not open for further replies.

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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