Hi,
I am trying to figure out how to add an email address to an outlook email dependant on the value of a designated cell.
I can generate and send the email no problem but can not seem to add a cc recipient. any ideas?
Sub SendCompliants()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String
Dim OutlApp As Object
Dim Title As String
Dim TitlePath As String
Dim NewMail As Object
Dim DistList As String
Dim LookupRng As String
Dim Segment As String
Dim Media As String
Dim Defence As String
'CC. Variable
Media = Range("G17").Value
Defence = Range("E17").Value
'Title of the document
Title = Range("C9").Value
TitlePath = "P:\Operational\Helpdesk\AA Sales\General Enquiries\Archived PDF Files (Do Not Use)\" & Title & ".pdf"
'LookupRng = Worksheets("Lookups").Range("A1:C14")
'LookupRng = "A1:D11"
'Segment = Range("E9").Value
'DistList = WorksheetFunction.VLookup(Segment, Worksheets("Lookups").Range(LookupRng), 3, 0)
ChDir "P:\Operational\Helpdesk\AA Sales\General Enquiries\Archived PDF Files (Do Not Use)"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
TitlePath, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set OutlApp = CreateObject("Outlook.application")
' Prepare e-mail with PDF attachment
Set NewMail = OutlApp.CreateItem(0)
NewMail.Subject = "Current Client Query - " & Title
NewMail.to = "Please use Account Locator for recipient"
NewMail.SentOnBehalfOfName = "SPSHelpdesk.Sales.UK@sodexo.com"
'NewMail.to = DistList
NewMail.CC = "Rebecca.Symon@sodexo.com"
NewMail.CC = "pressoffice@sodexo.com"
NewMail.Body = "Good Day," & vbLf & vbLf _
& "Please find attatched a PDF file of a Client Query." & vbLf & vbLf _
& "Kind Regards," & vbLf _
& "Sales Admin Team" & vbLf & vbLf
NewMail.Attachments.Add TitlePath
NewMail.Display
' Try to send
On Error Resume Next
'NewMail.Send
Application.Visible = True
If Err Then
MsgBox "Unable to generate email please check form", vbExclamation
Else
MsgBox "E-mail has been opened, please manually send", vbInformation
End If
On Error GoTo 0
' Release the memory of object variable
Set OutlApp = Nothing
End Sub
This is my current coding and when I try to run it I get an error box "Block If without End If"
any help on this issue would be greatly appreciated.
Thank you.
I am trying to figure out how to add an email address to an outlook email dependant on the value of a designated cell.
I can generate and send the email no problem but can not seem to add a cc recipient. any ideas?
Sub SendCompliants()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String
Dim OutlApp As Object
Dim Title As String
Dim TitlePath As String
Dim NewMail As Object
Dim DistList As String
Dim LookupRng As String
Dim Segment As String
Dim Media As String
Dim Defence As String
'CC. Variable
Media = Range("G17").Value
Defence = Range("E17").Value
'Title of the document
Title = Range("C9").Value
TitlePath = "P:\Operational\Helpdesk\AA Sales\General Enquiries\Archived PDF Files (Do Not Use)\" & Title & ".pdf"
'LookupRng = Worksheets("Lookups").Range("A1:C14")
'LookupRng = "A1:D11"
'Segment = Range("E9").Value
'DistList = WorksheetFunction.VLookup(Segment, Worksheets("Lookups").Range(LookupRng), 3, 0)
ChDir "P:\Operational\Helpdesk\AA Sales\General Enquiries\Archived PDF Files (Do Not Use)"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
TitlePath, Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set OutlApp = CreateObject("Outlook.application")
' Prepare e-mail with PDF attachment
Set NewMail = OutlApp.CreateItem(0)
NewMail.Subject = "Current Client Query - " & Title
NewMail.to = "Please use Account Locator for recipient"
NewMail.SentOnBehalfOfName = "SPSHelpdesk.Sales.UK@sodexo.com"
'NewMail.to = DistList
NewMail.CC = "Rebecca.Symon@sodexo.com"
NewMail.CC = "pressoffice@sodexo.com"
NewMail.Body = "Good Day," & vbLf & vbLf _
& "Please find attatched a PDF file of a Client Query." & vbLf & vbLf _
& "Kind Regards," & vbLf _
& "Sales Admin Team" & vbLf & vbLf
NewMail.Attachments.Add TitlePath
NewMail.Display
' Try to send
On Error Resume Next
'NewMail.Send
Application.Visible = True
If Err Then
MsgBox "Unable to generate email please check form", vbExclamation
Else
MsgBox "E-mail has been opened, please manually send", vbInformation
End If
On Error GoTo 0
' Release the memory of object variable
Set OutlApp = Nothing
End Sub
This is my current coding and when I try to run it I get an error box "Block If without End If"
any help on this issue would be greatly appreciated.
Thank you.