I have the code listed below to create an email. I want to send it to the email address that matches the value in a specific cell. For example, if cell B14 on Sheets("SINGLE") equals John Doe I want it to find his email address listed in the table Y1:Z20 on the same sheet and send the email to that address. I am not sure how to enter that into this code below. Any help would be appreciated. Thanks.
Sub Email()
Dim OutApp As Object
Dim OutMail As Object
Dim PDFFile As String
Dim FilePath As String
FilePath = "C:\Users\Desktop\TEST\Production.pdf"
'Create PDF'
Sheets("SINGLE").Range("B13:M35").ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
FilePath _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
'set up outlook'
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Create Message'
On Error Resume Next
With OutMail
.BodyFormat = olFormatHTML
.display
End With
strsignature = OutMail.htmlbody
With OutMail
.BodyFormat = olFormatHTML
.display 'Use only during debugging ##############################
.to = "" 'Insert required address here ########
.CC = ""
.BCC = ""
.Subject = "Production Email" & " - " & Sheets("SINGLE").Range("C1")
.htmlbody = "" & "Attached is your production for " & Sheets("SINGLE").Range("C1") & "." & vbCr & vbCr & "Please let me know if there are any questions. Thanks!" & vbCr & vbCr & vbCr & vbCr & strsignature
.Attachments.Add FilePath
'.Send 'Uncomment to send e-mail ##############################
End With
Kill "C:\Users\Desktop\TEST\Production.pdf"
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Bookmarks