SendEmail Macro customization

ArturoPeña

New member
Local time
Today, 07:39
Joined
Jun 6, 2012
Messages
5
ok, a little context: i have a Data Event macro set up to send an email whenever a new record is created.

its set up like this:
SendEmail
to =([Maintbl].[CustEmail])
cc
Subject Test Email
Body ??

what i want to accomplish is to pull the customer name from a field on Maintbl so that it personalizes the Body of the email.
example:

"Dear (CustName),

fixed text body information goes in here"

is there a way to do this?
 
ok, i was able to accomplish up to a certain degree... i was able to pull the name, from a field in my table, and since i can only type 255 chars, i had to pull the body of the email from a field in a different table. my problem right now, is that i want to create a line break, in order to give some formatting to the body of the email, but i get either a invalid argument in body error, or cannot parse the expression. can you please help?
 
i've tried including vbNewLine but id doesn't work
 
Here is what I currently have. I want to add a loop within the body of the email that will continue to find occurences of the same company name and add those lines OR something that will identify the range that includes all of the same company name and paste those lines into the body of the email. Either way it needs to continue through the full list until an emails is sent to each company. Those are my ideas but I'm open to suggestions if there is a better way!

Code:

Sub TestFile()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim cell As Range

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

On Error GoTo cleanup
For Each cell In Sheets("Daily Error Report").Columns("L").Cells.SpecialCells(xlCellTypeConstants)
If cell.Offset(0, 1).Value = "" Then
If cell.Value Like "*@*" And Dir(cell.Offset(0, 0).Value) = "" Then
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = cell.Value
.Subject = "Invoice reports"
.Body = "The following invoices were processed today" & newline_
.Body = cell.Offset(0, -6).Value & " - " & cell.Offset(0, -2).Value
.Send
End With
Set OutMail = Nothing
End If
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
 

Users who are viewing this thread

Back
Top Bottom